feat: enrich TeamDetail with multi-coach list and player height/jersey #292
No reviewers
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo_admin/basketball-api!292
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "284-team-detail-contract"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Changes the
TeamDetailAPI response contract to returncoaches(plural list) instead ofcoach(singular), and enrichesCoachBriefwithrole/phoneandPlayerBriefwithheight/jersey_number. All fields already exist in the DB -- this exposes them through the response models to match what the frontend expects.Changes
src/basketball_api/routes/teams.py--TeamDetail.coach: CoachBrief | Nonechanged tocoaches: list[CoachBrief]. AddedroleandphonetoCoachBrief. Addedheightandjersey_numbertoPlayerBrief. Added_coaches_list()helper to bridge the singular DB FK to the plural API contract. Updated_coach_brief()and_player_brief()helpers to populate new fields.tests/test_teams.py-- Updated existing coach assertion intest_coach_sees_own_teamsto usecoaches[0]. Added 4 new tests: no-coach returns empty list, single coach includes role/phone, player includes height/jersey_number, player with null height/jersey returns null.Test Plan
pytest tests/test_teams.py-- 45 tests pass (4 new)test_checkout.py(tracked by #274), unrelated to this changeruff formatandruff checkcleanReview Checklist
TeamDetail.coachchanged tocoaches: list[CoachBrief]CoachBriefincludesroleandphonePlayerBriefincludesheightandjersey_numberRelated Notes
Related
Closes #284
PR #292 Review
DOMAIN REVIEW
Stack: Python / FastAPI / SQLAlchemy / Pydantic
Contract change:
TeamDetail.coach: CoachBrief | Nonechanged tocoaches: list[CoachBrief]. This is a breaking API change for any consumer currently reading thecoachkey. The PR body acknowledges this is intentional to match what the frontend expects.Model enrichment:
CoachBriefgainsroleandphone;PlayerBriefgainsheightandjersey_number. All four fields exist in the DB models (Coach.role,Coach.phone,Player.height,Player.jersey_number) -- confirmed via model inspection. No new DB columns or migrations needed._coaches_list()helper: Clean bridge from singular FK to plural API contract. The# type: ignore[list-item]is justified --_coach_brief()returnsCoachBrief | Nonebut theNoneguard runs first, so the value is alwaysCoachBriefinside the list. Docstring is clear.coach.role.value: Correctly serializes the enum to its string value.coach.phoneis a plain string column, no enum conversion needed. Both match the model definitions.TeamResponsestill uses singularcoach: This is not in scope for this PR (the issue targetsTeamDetailonly), but worth noting that list/PATCH endpoints still returncoach: CoachBrief | None. The PATCH tests at lines 318, 333, 340, 382 still assertresp.json()["coach"]-- these remain valid sinceTeamResponseis unchanged. No inconsistency within this PR's scope.Test coverage: 4 new tests covering:
Plus 1 existing test updated (
test_coach_sees_own_teams) to assert the newcoacheslist shape and verifyroleis populated. Total: 45 team tests reported passing.PEP compliance: Type hints present on all new fields and function signatures. Docstring on
_coaches_list().= Nonedefaults on optional Pydantic fields follow PEP 484 conventions.BLOCKERS
None.
NITS
_coach_briefreturn type: Now that_coaches_listexists and handles theNonecase,_coach_briefis only ever called with a non-None coach. Consider narrowing its signature to_coach_brief(coach: Coach) -> CoachBriefand dropping theNoneguard, which would also eliminate the# type: ignore. Low priority since the current code is correct.Consistency observation:
TeamResponse(used by list/PATCH endpoints) still returns singularcoach. If the frontend migration tocoachesis complete, a follow-up ticket to alignTeamResponsewould prevent consumer confusion. Not in scope for this PR.SOP COMPLIANCE
284-team-detail-contractfollows{issue-number}-{kebab-case-purpose}TeamDetailresponse enrichmentPROCESS OBSERVATIONS
test_checkout.pyis tracked by #274. Not introduced by this PR.coach->coaches) should be coordinated with frontend deployment. The PR body states the frontend already expects the plural form, which mitigates risk.VERDICT: APPROVED