feat: add country field to player registration #231
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!231
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "229-add-player-country"
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
Add an ISO 3166-1 alpha-2
countrycolumn (VARCHAR(2), server default "US") to the Player model. Wired through the HTML registration form, JSON API, player profile, public API, and admin views. Existing players are backfilled to "US" via migration.Changes
src/basketball_api/models.py-- Addedcountrycolumn to Player model, placed afterhometownalembic/versions/028_add_country_to_players.py-- Migration: add column with server_default, backfill NULLssrc/basketball_api/routes/register.py-- Country field in HTML form (after hometown), extracted in POST handler, added toAPIRegistrationRequestPydantic model, passed through both form and JSON registration pathssrc/basketball_api/routes/players.py-- AddedcountrytoPlayerProfileResponse,PlayerProfileUpdate, and_player_profile_responsehelpersrc/basketball_api/routes/public.py-- AddedcountrytoPublicPlayerResponseand_public_playerhelpersrc/basketball_api/routes/admin.py-- AddedcountrytoAdminPlayerItemresponse model and admin players querytests/test_country.py-- New test file: form registration with/without country, JSON API with/without country, HTML field presencetests/test_public.py-- Updated allowlist assertion to includecountryTest Plan
ruff formatandruff checkcleanReview Checklist
Related Notes
None.
Related
Closes #229
QA Review -- PR #231
Summary
Add
countryfield (ISO 3166-1 alpha-2, VARCHAR(2), default "US") to Player model, wired through all API surfaces.Findings
No blocking issues found.
Model & Migration
hometownwithserver_default="US"-- safe for existing rowsMapped[str | None]type annotation matches nullable column with server defaultRegistration (HTML form + JSON API)
maxlength="2",text-transform:uppercase, and helpful ISO note.strip().upper() or None-- correct normalizationcountryfor returning parentsAPIRegistrationRequestaddscountry: Optional[str] = None-- backward compatibleProfile, Public, Admin
PlayerProfileResponseandPlayerProfileUpdateboth includecountrymodel_dump(exclude_unset=True)+setattrpattern -- no extra wiring neededPublicPlayerResponseincludescountrywith mapping fromplayer.countryAdminPlayerItemincludescountryin response model and query builderTests
test_country.py: form with country="TR", form without country (default), HTML field presence, API with country, API without countrytest_public.pyallowlist updated to includecountryNits (non-blocking)
test_registration_without_country_defaults_to_ustest assertsplayer.country in ("US", None)-- the loose assertion is fine since SQLAlchemyserver_defaultonly fires at the DB level, and the test DB does execute it, but the dual-check is a reasonable defensive pattern.VERDICT: APPROVED
forgejo_admin referenced this pull request2026-03-28 22:38:09 +00:00