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:
parent
3abc7b18c6
commit
b0d5d51a21
1 changed files with 13 additions and 19 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue