Use ISIN numbers instead of share symbols and add comment field to database.
Fixes #65
This commit is contained in:
@@ -2,17 +2,16 @@ __author__ = "Florian Kaiser"
|
||||
__copyright__ = "Copyright 2022, Project Aktienbot"
|
||||
__credits__ = ["Florian Kaiser", "Florian Kellermann", "Linus Eickhof", "Kevin Pauer"]
|
||||
__license__ = "GPL 3.0"
|
||||
__version__ = "1.0.0"
|
||||
__version__ = "1.0.1"
|
||||
|
||||
import os
|
||||
|
||||
from apiflask import APIBlueprint, abort
|
||||
|
||||
from app.auth import auth
|
||||
from app.db import database as db
|
||||
from app.helper_functions import make_response, get_email_or_abort_401
|
||||
from app.models import Share
|
||||
from app.schema import SymbolSchema, SymbolResponseSchema, DeleteSuccessfulSchema
|
||||
from app.schema import SymbolSchema, SymbolResponseSchema, DeleteSuccessfulSchema, SymbolRemoveSchema
|
||||
|
||||
shares_blueprint = APIBlueprint('share', __name__, url_prefix='/api')
|
||||
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
|
||||
@@ -27,16 +26,20 @@ 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")
|
||||
if not check_if_isin_data_exists(data):
|
||||
abort(400, message="ISIN missing")
|
||||
|
||||
if not check_if_comment_data_exists(data):
|
||||
abort(400, message="Comment missing")
|
||||
|
||||
# Check if share already exists
|
||||
check_share = db.session.query(Share).filter_by(symbol=data['symbol'], email=email).first()
|
||||
check_share = db.session.query(Share).filter_by(isin=data['isin'], email=email).first()
|
||||
if check_share is None:
|
||||
# Keyword doesn't exist yet for this user -> add it
|
||||
new_symbol = Share(
|
||||
email=email,
|
||||
symbol=data['symbol']
|
||||
isin=data['isin'],
|
||||
comment=data['comment']
|
||||
)
|
||||
db.session.add(new_symbol)
|
||||
db.session.commit()
|
||||
@@ -48,23 +51,23 @@ def add_symbol(data):
|
||||
|
||||
@shares_blueprint.route('/share', methods=['DELETE'])
|
||||
@shares_blueprint.output(DeleteSuccessfulSchema, 200)
|
||||
@shares_blueprint.input(schema=SymbolSchema)
|
||||
@shares_blueprint.input(schema=SymbolRemoveSchema)
|
||||
@shares_blueprint.auth_required(auth)
|
||||
@shares_blueprint.doc(summary="Removes existing symbol", description="Removes existing symbol for current user")
|
||||
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")
|
||||
if not check_if_isin_data_exists(data):
|
||||
abort(400, message="ISIN missing")
|
||||
|
||||
# Check if share exists
|
||||
check_share = db.session.query(Share).filter_by(symbol=data['symbol'], email=email).first()
|
||||
check_share = db.session.query(Share).filter_by(isin=data['isin'], email=email).first()
|
||||
if check_share is None:
|
||||
abort(500, "Symbol doesn't exist for this user")
|
||||
else:
|
||||
# Delete share
|
||||
db.session.query(Share).filter_by(symbol=data['symbol'], email=email).delete()
|
||||
db.session.query(Share).filter_by(isin=data['isin'], email=email).delete()
|
||||
db.session.commit()
|
||||
|
||||
return make_response({}, 200, "Successfully removed symbol")
|
||||
@@ -89,11 +92,21 @@ def get_symbol():
|
||||
return make_response(return_symbols, 200, "Successfully loaded symbols")
|
||||
|
||||
|
||||
def check_if_symbol_data_exists(data):
|
||||
if "symbol" not in data:
|
||||
def check_if_isin_data_exists(data):
|
||||
if "isin" not in data:
|
||||
return False
|
||||
|
||||
if data['symbol'] == "" or data['symbol'] is None:
|
||||
if data['isin'] == "" or data['isin'] is None:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def check_if_comment_data_exists(data):
|
||||
if "comment" not in data:
|
||||
return False
|
||||
|
||||
if data['comment'] == "" or data['comment'] is None:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
Reference in New Issue
Block a user