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())