From 3d85fce4ebac180b102611751141dc1d2d6a318a Mon Sep 17 00:00:00 2001 From: Swapnil Date: Tue, 30 Jan 2024 22:31:49 +0530 Subject: [PATCH] db: api to get all entires --- database/main.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/database/main.py b/database/main.py index 1711b80..9e1835f 100644 --- a/database/main.py +++ b/database/main.py @@ -107,5 +107,22 @@ def update_token_by_id(id): db.session.commit() return '', 204 +# get all tokens +@app.route('/token/all', methods=['GET']) +def get_all_tokens(): + tokens = Token.query.all() + tokens_info = [{ + 'id': token.id, + 'email': token.email, + 'access_token': token.access_token, + 'refresh_token': token.refresh_token, + 'expiration_seconds': int(token.expiration_seconds), + 'readwise_api_key': token.readwise_api_key, + 'active': token.active, + 'created_at': int(token.created_at.timestamp()), + 'updated_at': int(token.updated_at.timestamp()) + } for token in tokens] + return jsonify({'tokens': tokens_info}), 200 + if __name__ == '__main__': app.run(host='0.0.0.0', port=5000, debug=True)