diff --git a/backend/routes/audit.py b/backend/routes/audit.py index 3b35075..2b87a4a 100644 --- a/backend/routes/audit.py +++ b/backend/routes/audit.py @@ -94,6 +94,17 @@ def _to_sum_record_response(record: SumRecord, email: str) -> SumRecordResponse: ) +def _to_price_history_response(record: PriceHistory) -> PriceHistoryResponse: + return PriceHistoryResponse( + id=record.id, + source=record.source, + pair=record.pair, + price=record.price, + timestamp=record.timestamp, + created_at=record.created_at, + ) + + @router.get("/counter", response_model=PaginatedCounterRecords) async def get_counter_records( page: int = Query(1, ge=1), @@ -173,17 +184,7 @@ async def get_price_history( result = await db.execute(query) records = result.scalars().all() - return [ - PriceHistoryResponse( - id=record.id, - source=record.source, - pair=record.pair, - price=record.price, - timestamp=record.timestamp, - created_at=record.created_at, - ) - for record in records - ] + return [_to_price_history_response(record) for record in records] @router.post("/price-history/fetch", response_model=PriceHistoryResponse) @@ -216,11 +217,4 @@ async def fetch_price_now( result = await db.execute(query) record = result.scalar_one() - return PriceHistoryResponse( - id=record.id, - source=record.source, - pair=record.pair, - price=record.price, - timestamp=record.timestamp, - created_at=record.created_at, - ) + return _to_price_history_response(record)