Spaces:
Sleeping
Sleeping
get income_statement report by report_id
#11
by praneethys - opened
app/api/routers/income_statement.py
CHANGED
|
@@ -47,3 +47,19 @@ async def get_income_statements(
|
|
| 47 |
if len(all_rows) == 0:
|
| 48 |
raise HTTPException(status_code=status.HTTP_204_NO_CONTENT, detail="No income statements found for this user")
|
| 49 |
return all_rows
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
if len(all_rows) == 0:
|
| 48 |
raise HTTPException(status_code=status.HTTP_204_NO_CONTENT, detail="No income statements found for this user")
|
| 49 |
return all_rows
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
@r.get(
|
| 53 |
+
"/{report_id}",
|
| 54 |
+
response_model=IncomeStatementResponse,
|
| 55 |
+
responses={
|
| 56 |
+
200: {"description": "Income statement found"},
|
| 57 |
+
404: {"description": "Income statement not found"},
|
| 58 |
+
500: {"description": "Internal server error"},
|
| 59 |
+
},
|
| 60 |
+
)
|
| 61 |
+
async def get_income_statement(report_id: int, db: AsyncSession = Depends(get_db_session)) -> IncomeStatementResponse:
|
| 62 |
+
income_statement = await IncomeStatementModel.get(db, id=report_id)
|
| 63 |
+
if not income_statement:
|
| 64 |
+
raise HTTPException(status_code=404, detail="Income statement not found")
|
| 65 |
+
return income_statement
|
app/model/income_statement.py
CHANGED
|
@@ -34,3 +34,9 @@ class IncomeStatement(Base, BaseModel):
|
|
| 34 |
query = sql.select(cls).where(cls.user_id == user_id)
|
| 35 |
income_statements = await db.scalars(query)
|
| 36 |
return income_statements
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
query = sql.select(cls).where(cls.user_id == user_id)
|
| 35 |
income_statements = await db.scalars(query)
|
| 36 |
return income_statements
|
| 37 |
+
|
| 38 |
+
@classmethod
|
| 39 |
+
async def get(cls: "type[IncomeStatement]", db: AsyncSession, id: int) -> "IncomeStatement":
|
| 40 |
+
query = sql.select(cls).where(cls.id == id)
|
| 41 |
+
income_statement = await db.scalar(query)
|
| 42 |
+
return income_statement
|