Changes

Jump to navigation Jump to search
1,128 bytes added ,  21:56, 31 July 2022
no edit summary
Line 68: Line 68:  
The proposed API definition is below. Note that the requests are represented as Python objects as used in FastAPI - in reality, this is a JSON payload:
 
The proposed API definition is below. Note that the requests are represented as Python objects as used in FastAPI - in reality, this is a JSON payload:
   −
<nowiki><code></nowiki>
+
<pre>
   −
test
+
class SearchBase(BaseModel):
 +
    response_fields: Optional[Set[str]]
   −
<nowiki></code></nowiki>
+
 
 +
class AutocompleteRequest(SearchBase):
 +
    text: str
 +
    search_fields: List[str] = constants.AUTOCOMPLETE_FIELDS
 +
 
 +
 
 +
class StringFilter(BaseModel):
 +
    field: str
 +
    value: str
 +
    # One of eq, ne, like, without
 +
    operator: str = 'eq'
 +
 
 +
 
 +
class NumericFilter(BaseModel):
 +
    field: str
 +
    value: float
 +
    # One of eq, ne, lt, gt, without
 +
    operator: str = 'eq'
 +
 
 +
 
 +
class DateTimeFilter(BaseModel):
 +
    field: str
 +
    value: datetime.datetime
 +
    # One of eq, ne, lt, gt, without
 +
    operator: str = 'eq'
 +
 
 +
 
 +
class SearchRequest(SearchBase):
 +
    # Works as an intersection/AND query
 +
    string_filters: List[StringFilter]
 +
    numeric_filters: List[NumericFilter]
 +
    date_time_filters: List[DateTimeFilter]
 +
 
 +
</pre>
 +
 
 +
These are then used as follows:
 +
<pre>
 +
# Gets the product matching a barcode, included to demonstrate potential usage to replace the main read API, this should not be exposed unless it is decided to send all reads through this service
 +
GET /barcode/<barcode>
 +
 
 +
# Autocomplete request
 +
POST /autocomplete, body=AutocompleteRequest
 +
 
 +
# Fully fledged search
 +
POST /search, body=SearchRequest
 +
 
 +
</pre>
 
   
 
   
  
17

edits

Navigation menu