Skip to content

Commit

Permalink
🏗️ add filters to API handkers
Browse files Browse the repository at this point in the history
  • Loading branch information
matv864 committed Sep 2, 2024
1 parent b90c148 commit f8536c8
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions backend/src/api/main_router.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from typing import Optional
from uuid import UUID
from datetime import date

from fastapi import APIRouter, Request, status

from src.database import My_crud
Expand Down Expand Up @@ -69,8 +73,21 @@ async def get_news():
response_model=list[ReportComment_schema],
status_code=status.HTTP_200_OK
)
async def get_report_comments():
async def get_report_comments(
reportType_id: Optional[UUID] = None,
start_date: Optional[date] = None,
finish_date: Optional[date] = None
):
filters = []
if reportType_id:
filters.append(ReportComment.type_id == reportType_id)
if start_date:
filters.append(ReportComment.date >= start_date)
if finish_date:
filters.append(ReportComment.date <= finish_date)

return await My_crud(ReportComment).get(
filters=filters,
multi=True
)

Expand All @@ -92,5 +109,17 @@ async def get_report_types():
response_model=list[Transaction_schema],
status_code=status.HTTP_200_OK
)
async def get_transactions():
return await My_crud(Transaction).get(multi=True)
async def get_transactions(
start_date: Optional[date] = None,
finish_date: Optional[date] = None
):
filters = []
if start_date:
filters.append(Transaction.date_of_payment >= start_date)
if finish_date:
filters.append(Transaction.date_of_payment <= finish_date)

return await My_crud(Transaction).get(
filters=filters,
multi=True
)

0 comments on commit f8536c8

Please sign in to comment.