Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Adding some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
chouinar committed Sep 6, 2024
1 parent 51f2eb0 commit 43137f0
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions api/src/api/schemas/search_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,37 @@ def with_one_of(


class IntegerSearchSchemaBuilder(BaseSearchSchemaBuilder):
"""
Builder for setting up a filter in a search endpoint schema for an integer.
Our schemas are setup to look like:
{
"filters": {
"field": {
"min": 1,
"max": 5
}
}
}
This helps generate the filters for a given field. At the moment,
only a min and max filter are implemented, and can be used to filter
on a range of values.
Usage::
# In a search request schema, you would use it like so
class OpportunitySearchFilterSchema(Schema):
example_int_field = fields.Nested(
IntegerSearchSchemaBuilder("ExampleIntFieldSchema")
.with_minimum_value(example=1)
.with_maximum_value(example=25)
.build()
)
"""

def with_minimum_value(
self, example: int | None = None, positive_only: bool = True
) -> "IntegerSearchSchemaBuilder":
Expand Down Expand Up @@ -156,6 +187,38 @@ def with_maximum_value(


class BoolSearchSchemaBuilder(BaseSearchSchemaBuilder):
"""
Builder for setting up a filter in a search endpoint schema.
Our schemas are setup to look like:
{
"filters": {
"field": {
"one_of": ["True", "False"]
}
}
}
This helps generate the filters for a given field. At the moment,
only a one_of filter is implemented - note that any truthy value
as determined by Marshmallow is accepted (including "yes", "y", 1 - for true)
While it doesn't quite make sense to filter by multiple boolean values in most cases,
we err on the side of consistency with the structure of the query to match other types.
Usage::
# In a search request schema, you would use it like so
class OpportunitySearchFilterSchema(Schema):
example_bool_field = fields.Nested(
BoolSearchSchemaBuilder("ExampleBoolFieldSchema")
.with_one_of(example=True)
.build()
)
"""

def with_one_of(self, example: bool | None = None) -> "BoolSearchSchemaBuilder":
metadata = {}
if example is not None:
Expand Down

0 comments on commit 43137f0

Please sign in to comment.