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.)
This commit is contained in:
counterweight 2025-12-22 16:17:43 +01:00
parent 3abc7b18c6
commit b0d5d51a21
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C

View file

@ -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)