Return list of tracking numbers in reverse order. Recent first
This commit is contained in:
parent
eabe2af9b1
commit
478a3fb225
@ -59,13 +59,14 @@ class EmailToken(db.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def jsonify_all(cls, token_type=None):
|
def jsonify_all(cls, token_type=None, desc=False):
|
||||||
|
query = cls.query
|
||||||
if token_type:
|
if token_type:
|
||||||
print('Filtering query by token type', file=sys.stderr)
|
print('Filtering query by token type', file=sys.stderr)
|
||||||
results = cls.query.filter_by(token_type=token_type).all()
|
query = query.filter_by(token_type=token_type)
|
||||||
else:
|
if desc:
|
||||||
results = cls.query.all()
|
query = query.order_by(cls.id.desc())
|
||||||
return jsonify(tokens=[token.as_dict() for token in results])
|
return jsonify(tokens=[token.as_dict() for token in query.all()])
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
@ -114,8 +115,9 @@ def create_tokens():
|
|||||||
def list_all_tokens():
|
def list_all_tokens():
|
||||||
"""Lists all tokens with an optional type filter"""
|
"""Lists all tokens with an optional type filter"""
|
||||||
token_type = request.args.get('filter_type')
|
token_type = request.args.get('filter_type')
|
||||||
|
desc = request.args.get('desc', False)
|
||||||
print('Asked to filter by ', token_type, file=sys.stderr)
|
print('Asked to filter by ', token_type, file=sys.stderr)
|
||||||
return EmailToken.jsonify_all(token_type=token_type)
|
return EmailToken.jsonify_all(token_type=token_type, desc=desc)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/token/<int:token_id>', methods=['GET'])
|
@app.route('/token/<int:token_id>', methods=['GET'])
|
||||||
|
@ -20,7 +20,10 @@ def check():
|
|||||||
def get_tokens():
|
def get_tokens():
|
||||||
resp = requests.get(
|
resp = requests.get(
|
||||||
indexer_url+'/token',
|
indexer_url+'/token',
|
||||||
params={'filter_type': 'SHIPPING'},
|
params={
|
||||||
|
'filter_type': 'SHIPPING',
|
||||||
|
'desc': True,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
tokens = resp.json().get('tokens')
|
tokens = resp.json().get('tokens')
|
||||||
|
Loading…
Reference in New Issue
Block a user