fix: include player_name in /teams/{id}/evolutions response (#115)

JOIN the Player table in the evolutions query so p_name can be
included in each serialized item without N+1 queries.

Closes #115

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2026-03-19 13:03:34 -05:00
parent cf0b1d1d1c
commit 383fb2bc3f

View File

@ -1049,7 +1049,6 @@ async def team_buy_players(team_id: int, ids: str, ts: str):
detail=f"You are not authorized to buy {this_team.abbrev} cards. This event has been logged.",
)
all_ids = ids.split(",")
conf_message = ""
total_cost = 0
@ -1561,12 +1560,14 @@ async def list_team_evolutions(
logging.warning("Bad Token: [REDACTED]")
raise HTTPException(status_code=401, detail="Unauthorized")
from ..db_engine import EvolutionCardState, EvolutionTrack
from ..db_engine import EvolutionCardState, EvolutionTrack, Player
from ..routers_v2.evolution import _build_card_state_response
query = (
EvolutionCardState.select(EvolutionCardState, EvolutionTrack)
EvolutionCardState.select(EvolutionCardState, EvolutionTrack, Player)
.join(EvolutionTrack)
.switch(EvolutionCardState)
.join(Player)
.where(EvolutionCardState.team == team_id)
.order_by(EvolutionCardState.player_id)
)
@ -1581,5 +1582,9 @@ async def list_team_evolutions(
offset = (page - 1) * per_page
page_query = query.offset(offset).limit(per_page)
items = [_build_card_state_response(state) for state in page_query]
items = []
for state in page_query:
item = _build_card_state_response(state)
item["player_name"] = state.player.p_name
items.append(item)
return {"count": total, "items": items}