"백엔드_핵심_로직_구현_프론트엔드_연동_및_도커_배포_최적화_완료"
This commit is contained in:
54
backend/app/api/endpoints/account.py
Normal file
54
backend/app/api/endpoints/account.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select
|
||||
from typing import List
|
||||
|
||||
from app.db.database import get_db
|
||||
from app.db.models import AccountStatus, Holding
|
||||
from pydantic import BaseModel
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class AccountStatusSchema(BaseModel):
|
||||
totalAssets: float
|
||||
buyingPower: float
|
||||
dailyProfit: float
|
||||
dailyProfitRate: float
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
class HoldingSchema(BaseModel):
|
||||
stockCode: str
|
||||
stockName: str
|
||||
quantity: int
|
||||
avgPrice: float
|
||||
currentPrice: float
|
||||
profit: float
|
||||
profitRate: float
|
||||
marketValue: float
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
@router.get("/summary", response_model=AccountStatusSchema)
|
||||
async def get_account_summary(db: AsyncSession = Depends(get_db)):
|
||||
stmt = select(AccountStatus).where(AccountStatus.id == 1)
|
||||
result = await db.execute(stmt)
|
||||
status = result.scalar_one_or_none()
|
||||
|
||||
if not status:
|
||||
# Return default zeroed if not initialized
|
||||
return AccountStatusSchema(totalAssets=0, buyingPower=0, dailyProfit=0, dailyProfitRate=0)
|
||||
|
||||
return status
|
||||
|
||||
@router.get("/holdings", response_model=List[HoldingSchema])
|
||||
async def get_holdings(market: str = None, db: AsyncSession = Depends(get_db)):
|
||||
# TODO: Filter by market if Holding table supports it.
|
||||
# Current Holding model doesn't have 'market' column explicitly, but we can assume mixed or add it.
|
||||
# For now, return all.
|
||||
stmt = select(Holding)
|
||||
result = await db.execute(stmt)
|
||||
holdings = result.scalars().all()
|
||||
return holdings
|
||||
Reference in New Issue
Block a user