diff --git a/api/app/blueprints/portfolio.py b/api/app/blueprints/portfolio.py index 465ce47..2d2cde9 100644 --- a/api/app/blueprints/portfolio.py +++ b/api/app/blueprints/portfolio.py @@ -2,10 +2,11 @@ import os from apiflask import APIBlueprint -from app.schema import PortfolioResponseSchema +from app.models import SharePrice +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.auth import auth +from app.schema import PortfolioResponseSchema portfolio_blueprint = APIBlueprint('portfolio', __name__, url_prefix='/api') __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__))) @@ -23,11 +24,18 @@ def get_portfolio(): if transactions is not None: for row in transactions: - return_portfolio.append({ + data = { "symbol": row[0], "count": row[1], - # "price": row[2], - "last_transaction": row[3] - }) + # "calculated_price": row[2], + "last_transaction": row[3], + 'current_price': 0 + } + + query_share_price = db.session.query(SharePrice).filter_by(symbol=row[0]).first() + if query_share_price is not None: + data['current_price'] = query_share_price.as_dict()['price'] + + return_portfolio.append(data) return make_response(return_portfolio, 200, "Successfully loaded symbols")