Add trade type on api options

This commit is contained in:
RubenPX 2022-04-28 11:22:53 +02:00
parent c6bc695881
commit c8dc1b11e2
1 changed files with 17 additions and 0 deletions

View File

@ -29,6 +29,7 @@ class LotView(View):
"""
format = EnumField(LotFormat, missing=None)
search = f.Str(missing=None)
type = f.Str(missing=None)
def post(self):
l = request.get_json()
@ -88,6 +89,7 @@ class LotView(View):
else:
query = Lot.query
query = self.visibility_filter(query)
query = self.type_filter(query, args)
if args['search']:
query = query.filter(Lot.name.ilike(args['search'] + '%'))
lots = query.paginate(per_page=6 if args['search'] else query.count())
@ -104,6 +106,21 @@ class LotView(View):
Lot.owner_id == g.user.id))
return query
def type_filter(self, query, args):
lot_type = args.get('type')
# temporary
if lot_type == "temporary":
return query.filter(Lot.trade == None)
if lot_type == "incoming":
return query.filter(Lot.trade and Trade.user_to == g.user)
if lot_type == "outgoing":
return query.filter(Lot.trade and Trade.user_from == g.user)
return query
def query(self, args):
query = Lot.query.distinct()
return query