Standardization of json responses

This commit is contained in:
2022-03-22 11:21:39 +01:00
parent bd5768527e
commit 40d3e3238d
8 changed files with 33 additions and 33 deletions

View File

@@ -1,13 +1,12 @@
import os
from apiflask import APIBlueprint, abort
from flask import jsonify
from auth import auth
from db import db
from helper_functions import get_user_id_from_username, get_username_or_abort_401
from helper_functions import get_user_id_from_username, get_username_or_abort_401, make_response
from models import Share
from scheme import SymbolSchema, SymbolResponseSchema, DeleteSuccessfulSchema
from schema import SymbolSchema, SymbolResponseSchema, DeleteSuccessfulSchema
shares_blueprint = APIBlueprint('share', __name__, url_prefix='/api')
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
@@ -35,9 +34,9 @@ def add_symbol(data):
db.session.add(new_symbol)
db.session.commit()
return jsonify({"status": 200, "text": "Successfully added symbol", "data": new_symbol.as_dict()})
return make_response(new_symbol.as_dict(), 200, "Successfully added symbol")
else:
return jsonify({"status": 500, "text": "Symbol already exist for this user"})
return make_response({}, 500, "Symbol already exist for this user")
@shares_blueprint.route('/share', methods=['DELETE'])
@@ -55,7 +54,7 @@ def remove_symbol(data):
db.session.query(Share).filter_by(symbol=symbol, user_id=get_user_id_from_username(username)).delete()
db.session.commit()
return jsonify({"status": 200, "text": "Successfully removed symbol", "data": {}})
return make_response({}, 200, "Successfully removed symbol")
@shares_blueprint.route('/shares', methods=['GET'])
@@ -72,7 +71,7 @@ def get_symbol():
for row in symbols:
return_symbols.append(row.as_dict())
return jsonify({"status": 200, "text": "Successfully loaded symbols", "data": return_symbols})
return make_response(return_symbols, 200, "Successfully loaded symbols")
def check_if_symbol_data_exists(data):