From b0d5d51a21382c4d0cb977c3828739c92172a15a Mon Sep 17 00:00:00 2001 From: counterweight Date: Mon, 22 Dec 2025 16:17:43 +0100 Subject: [PATCH] refactor: extract _to_price_history_response helper function Consistent with other response conversion functions in the codebase (_to_counter_record_response, _to_invite_response, etc.) --- backend/routes/audit.py | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) 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)