Skip to content

Commit 0417cf5

Browse files
committed
#824 Fixed format of latest currencies
1 parent 119c63f commit 0417cf5

2 files changed

Lines changed: 5 additions & 13 deletions

File tree

src/backend_api/app/api/routes/currency.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ async def get_latest_hours(
137137

138138
@router.get(
139139
"/latest_currencies/",
140-
response_model=dict[int, list[schemas.Currency]],
140+
response_model=list[schemas.Currency],
141141
tags=["latest_currencies"],
142142
dependencies=[
143143
Depends(get_current_active_user),
@@ -156,9 +156,7 @@ async def get_latest_currencies(
156156
db: Session = Depends(get_db),
157157
):
158158
"""
159-
Returns a dict mapping league id to most recent currencies relating to that league. Dict is empty if no currencies exist.
160-
161-
Does not guarantee an entry for every league id.
159+
Returns a list of currencies for all queried leagues (if data exists).
162160
"""
163161
return await CRUD_currency.get_latest_currencies(db, league_ids)
164162

src/backend_api/app/crud/extensions/crud_currency.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from collections import defaultdict
2-
31
from pydantic import TypeAdapter
42
from sqlalchemy import select
53
from sqlalchemy.orm import Session
@@ -62,7 +60,7 @@ async def get_latest_hours(
6260

6361
async def get_latest_currencies(
6462
self, db: Session, league_ids: list[int]
65-
) -> dict[int, list[Currency]]:
63+
) -> list[Currency]:
6664
latest_hours = self._latest_hours_stmt(league_ids).subquery()
6765

6866
stmt = select(model_Currency).join(
@@ -72,13 +70,9 @@ async def get_latest_currencies(
7270
)
7371
currencies = db.scalars(stmt).all()
7472

75-
latest_currencies: dict[int, list[Currency]] = defaultdict(list)
76-
for currency in currencies:
77-
latest_currencies[currency.leagueId].append(currency)
78-
79-
validate = TypeAdapter(dict[int, list[Currency]]).validate_python
73+
validate = TypeAdapter(list[Currency]).validate_python
8074

81-
return validate(latest_currencies)
75+
return validate(currencies)
8276

8377
async def get_currency_from_query(
8478
self, db: Session, query_list: list[CurrencyQuery]

0 commit comments

Comments
 (0)