Spaces:
Sleeping
Sleeping
| from typing import List | |
| from fastapi import APIRouter, Depends, HTTPException, status | |
| from sqlalchemy.ext.asyncio import AsyncSession | |
| from app.model.transaction import Transaction as TransactionModel | |
| from app.model.income_statement import IncomeStatement as IncomeStatementModel | |
| from app.schema.index import IncomeStatementCreateRequest, IncomeStatementResponse | |
| from app.engine.postgresdb import get_db_session | |
| from app.service.income_statement import call_llm_to_create_income_statement | |
| income_statement_router = r = APIRouter(prefix="/api/v1/income_statement", tags=["income_statement"]) | |
| async def create_income_statement(payload: IncomeStatementCreateRequest, db: AsyncSession = Depends(get_db_session)) -> None: | |
| try: | |
| await call_llm_to_create_income_statement(payload, db) | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| async def get_income_statements( | |
| user_id: int, db: AsyncSession = Depends(get_db_session) | |
| ) -> List[IncomeStatementResponse]: | |
| """ | |
| Retrieve all income statements. | |
| """ | |
| result = await IncomeStatementModel.get_by_user(db, user_id) | |
| if len(result) == 0: | |
| raise HTTPException(status_code=status.HTTP_204_NO_CONTENT, detail="No income statements found for this user") | |
| return result | |
| async def get_income_statement(report_id: int, db: AsyncSession = Depends(get_db_session)) -> IncomeStatementResponse: | |
| income_statement = await IncomeStatementModel.get(db, id=report_id) | |
| if not income_statement: | |
| raise HTTPException(status_code=404, detail="Income statement not found") | |
| return income_statement | |