Skip to content

Commit

Permalink
Support multiple values for filters
Browse files Browse the repository at this point in the history
  • Loading branch information
booxter committed Nov 20, 2024
1 parent 22454c2 commit fcd7564
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/letsrolld/webapi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ class FilmResource(Resource):
"required": False,
"schema": {"type": "integer", "default": 10},
},
# TODO: make filters accept multiple values
{
"name": "genre",
"in": "query",
Expand Down Expand Up @@ -186,17 +185,16 @@ def get(self, _parser):

query = db_.session.query(models.Film)
if args["genre"]:
query = query.join(models.Film.genres).filter(
models.Genre.name == args["genre"]
)
genres = args["genre"].split(",")
query = query.join(models.Film.genres).filter(models.Genre.name.in_(genres))
if args["country"]:
countries = args["country"].split(",")
query = query.join(models.Film.countries).filter(
models.Country.name == args["country"]
models.Country.name.in_(countries)
)
if args["offer"]:
query = query.join(models.Film.offers).filter(
models.Offer.name == args["offer"]
)
offers = args["offer"].split(",")
query = query.join(models.Film.offers).filter(models.Offer.name.in_(offers))

query = query.order_by(func.random()).limit(args["limit"])
return [_get_film(db_.session, d) for d in query], 200
Expand Down

0 comments on commit fcd7564

Please sign in to comment.