From 85046a0f75f29dc59ccc13367faa83736e27b4dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Thu, 16 Aug 2018 12:17:47 +0200 Subject: [PATCH] Implement older_than and newer_than in gifted-subs-api --- gifted-subs-api/app.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gifted-subs-api/app.py b/gifted-subs-api/app.py index a995ce2..179d84e 100644 --- a/gifted-subs-api/app.py +++ b/gifted-subs-api/app.py @@ -55,6 +55,8 @@ gifted_sub_parser.add_argument('time', type=flask_restful.inputs.datetime_from_i filter_parser = flask_restful.reqparse.RequestParser() filter_parser.add_argument('filter', type=str) +filter_parser.add_argument('older_than', type=flask_restful.inputs.datetime_from_iso8601) +filter_parser.add_argument('newer_than', type=flask_restful.inputs.datetime_from_iso8601) filter_parser.add_argument('sort_by', type=str) filter_parser.add_argument('sort_order', type=str) filter_parser.add_argument('page_number', type=int) @@ -120,6 +122,10 @@ class GiftedSubsResource(flask_restful.Resource): if args['filter']: q = q.filter(GiftedSub.giver.ilike('%{}%'.format(args['filter'])) |\ GiftedSub.receiver.ilike('%{}%'.format(args['filter']))) + if args['older_than']: + q = q.filter(GiftedSub.time < args['older_than']) + if args['newer_than']: + q = q.filter(GiftedSub.time > args['newer_than']) count = q.count() if args['sort_order'] == 'random': q = q.order_by(sqlalchemy.func.random())