Added comments

This commit is contained in:
2022-04-12 11:36:23 +02:00
parent f47ab2362b
commit 24c2702f10
11 changed files with 132 additions and 57 deletions

View File

@@ -26,17 +26,17 @@ __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file
def add_symbol(data):
email = get_email_or_abort_401()
# Check if required data is available
if not check_if_symbol_data_exists(data):
abort(400, message="Symbol missing")
symbol = data['symbol']
check_share = db.session.query(Share).filter_by(symbol=symbol, email=email).first()
# Check if share already exists
check_share = db.session.query(Share).filter_by(symbol=data['symbol'], email=email).first()
if check_share is None:
# Keyword doesn't exist yet for this user
# Keyword doesn't exist yet for this user -> add it
new_symbol = Share(
email=email,
symbol=symbol
symbol=data['symbol']
)
db.session.add(new_symbol)
db.session.commit()
@@ -54,17 +54,17 @@ def add_symbol(data):
def remove_symbol(data):
email = get_email_or_abort_401()
# Check if required data is available
if not check_if_symbol_data_exists(data):
abort(400, message="Symbol missing")
symbol = data['symbol']
check_share = db.session.query(Share).filter_by(symbol=symbol, email=email).first()
# Check if share exists
check_share = db.session.query(Share).filter_by(symbol=data['symbol'], email=email).first()
if check_share is None:
abort(500, "Symbol doesn't exist for this user")
else:
db.session.query(Share).filter_by(symbol=symbol, email=email).delete()
# Delete share
db.session.query(Share).filter_by(symbol=data['symbol'], email=email).delete()
db.session.commit()
return make_response({}, 200, "Successfully removed symbol")
@@ -80,6 +80,8 @@ def get_symbol():
return_symbols = []
symbols = db.session.query(Share).filter_by(email=email).all()
# If no shares exist for this user -> return empty list
# Otherwise iterate over all shares, convert them to json and add them to the return list
if symbols is not None:
for row in symbols:
return_symbols.append(row.as_dict())