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 datetime
|
||||
import os
|
||||
|
||||
from apiflask import APIBlueprint, abort
|
||||
|
||||
from app.models import SharePrice
|
||||
from app.auth import auth
|
||||
from app.db import database as db
|
||||
from app.helper_functions import make_response
|
||||
from app.auth import auth
|
||||
from app.models import SharePrice
|
||||
from app.schema import SymbolPriceSchema
|
||||
|
||||
share_price_blueprint = APIBlueprint('share_price', __name__, url_prefix='/api')
|
||||
@@ -25,7 +24,7 @@ __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file
|
||||
@share_price_blueprint.doc(summary="Returns all transaction symbols", description="Returns all transaction symbols for all users")
|
||||
def get_transaction_symbols():
|
||||
# Get all transaction symbols
|
||||
symbols = db.session.execute("SELECT symbol FROM `transactions` GROUP BY symbol;").all()
|
||||
symbols = db.session.execute("SELECT isin FROM `transactions` GROUP BY isin;").all()
|
||||
|
||||
return_symbols = []
|
||||
for s in symbols:
|
||||
@@ -38,11 +37,11 @@ def get_transaction_symbols():
|
||||
@share_price_blueprint.output({}, 200)
|
||||
@share_price_blueprint.input(schema=SymbolPriceSchema)
|
||||
@share_price_blueprint.auth_required(auth)
|
||||
@share_price_blueprint.doc(summary="Returns all transaction symbols", description="Returns all transaction symbols for all users")
|
||||
@share_price_blueprint.doc(summary="Adds new price for isin", description="Adds new price to database")
|
||||
def add_symbol_price(data):
|
||||
# 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_price_data_exists(data):
|
||||
abort(400, message="Price missing")
|
||||
@@ -52,7 +51,7 @@ def add_symbol_price(data):
|
||||
|
||||
# Add share price
|
||||
share_price = SharePrice(
|
||||
symbol=data['symbol'],
|
||||
isin=data['isin'],
|
||||
price=data['price'],
|
||||
date=datetime.datetime.strptime(data['time'], '%Y-%m-%dT%H:%M:%S.%fZ'),
|
||||
)
|
||||
@@ -63,11 +62,11 @@ def add_symbol_price(data):
|
||||
return make_response(share_price.as_dict(), 200, "Successfully added price")
|
||||
|
||||
|
||||
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
|
||||
|
Reference in New Issue
Block a user