Wire /admin/teams GET + POST /admin/teams/save for SPA team management #121

Closed
opened 2026-03-19 20:06:23 +00:00 by forgejo_admin · 0 comments

Type

Feature

Lineage

plan-wkq → Phase 11 → Girls Tryout / Team Drop

Repo

forgejo_admin/basketball-api

User Story

As Coach Marcus (admin)
I want to use the admin teams page to create teams and assign players
So that coaches can see their rosters on the 7pm call tonight

Context

The SPA admin teams page at /admin/teams is fully built but calls two endpoints that don't exist on the backend:

  1. GET /admin/teams — frontend expects { teams: [...], players: [...] }
  2. POST /admin/teams/save — frontend sends { assignments: [{ player_id, team_id }] }

The existing team CRUD routes at /teams and /api/teams have all the business logic (create, list, assign, unassign). The admin endpoints just need to adapt the response format for the frontend and auto-resolve the tenant (only one tenant exists: westside-kings-queens).

Frontend team creation uses prompt() which generates temp IDs prefixed with t (e.g. t1710878400000). The save endpoint needs to create real teams for temp IDs and persist all player assignments.

File Targets

Files the agent should modify or create:

  • src/basketball_api/routes/admin.py — add GET /admin/teams and POST /admin/teams/save endpoints

Files the agent should NOT touch:

  • src/basketball_api/routes/teams.py — existing team routes, leave as-is
  • Frontend code — already working
  • Models — no migration needed, reuse existing Team/Player models

Acceptance Criteria

  • When admin visits /admin/teams in the SPA, teams and players load
  • When admin creates a team via prompt, assigns players, and clicks Save, changes persist
  • When admin reloads the page, saved assignments are still there
  • Existing /teams and /api/teams routes are unaffected

Test Expectations

  • Unit test: GET /admin/teams returns { teams, players } with correct structure
  • Unit test: POST /admin/teams/save creates new teams for temp IDs and assigns players
  • Unit test: POST /admin/teams/save with existing team IDs only updates assignments
  • Run command: pytest tests/ -k test_admin_teams

Constraints

  • Only one tenant exists (westside-kings-queens) — auto-resolve it, don't require tenant_id param
  • Team temp IDs from frontend start with t — detect and create real teams for these
  • Reuse existing models (Team, Player, Tenant) — no new models needed
  • Response format for GET must match what frontend expects: { teams: [{ id, name, coaches: [...] }], players: [{ id, name, division, position, team_id, team, height, ... }] }
  • Admin auth already handled by the admin router

Checklist

  • PR opened
  • Tests pass
  • No unrelated changes
  • phase-wkq-11-girls-tryout
  • Issue #115 (operational: create teams and assign players — depends on this code fix)
### Type Feature ### Lineage `plan-wkq` → Phase 11 → Girls Tryout / Team Drop ### Repo `forgejo_admin/basketball-api` ### User Story As Coach Marcus (admin) I want to use the admin teams page to create teams and assign players So that coaches can see their rosters on the 7pm call tonight ### Context The SPA admin teams page at /admin/teams is fully built but calls two endpoints that don't exist on the backend: 1. `GET /admin/teams` — frontend expects `{ teams: [...], players: [...] }` 2. `POST /admin/teams/save` — frontend sends `{ assignments: [{ player_id, team_id }] }` The existing team CRUD routes at `/teams` and `/api/teams` have all the business logic (create, list, assign, unassign). The admin endpoints just need to adapt the response format for the frontend and auto-resolve the tenant (only one tenant exists: westside-kings-queens). Frontend team creation uses `prompt()` which generates temp IDs prefixed with `t` (e.g. `t1710878400000`). The save endpoint needs to create real teams for temp IDs and persist all player assignments. ### File Targets Files the agent should modify or create: - `src/basketball_api/routes/admin.py` — add `GET /admin/teams` and `POST /admin/teams/save` endpoints Files the agent should NOT touch: - `src/basketball_api/routes/teams.py` — existing team routes, leave as-is - Frontend code — already working - Models — no migration needed, reuse existing Team/Player models ### Acceptance Criteria - [ ] When admin visits /admin/teams in the SPA, teams and players load - [ ] When admin creates a team via prompt, assigns players, and clicks Save, changes persist - [ ] When admin reloads the page, saved assignments are still there - [ ] Existing /teams and /api/teams routes are unaffected ### Test Expectations - [ ] Unit test: GET /admin/teams returns { teams, players } with correct structure - [ ] Unit test: POST /admin/teams/save creates new teams for temp IDs and assigns players - [ ] Unit test: POST /admin/teams/save with existing team IDs only updates assignments - Run command: `pytest tests/ -k test_admin_teams` ### Constraints - Only one tenant exists (westside-kings-queens) — auto-resolve it, don't require tenant_id param - Team temp IDs from frontend start with `t` — detect and create real teams for these - Reuse existing models (Team, Player, Tenant) — no new models needed - Response format for GET must match what frontend expects: `{ teams: [{ id, name, coaches: [...] }], players: [{ id, name, division, position, team_id, team, height, ... }] }` - Admin auth already handled by the admin router ### Checklist - [ ] PR opened - [ ] Tests pass - [ ] No unrelated changes ### Related - `phase-wkq-11-girls-tryout` - Issue #115 (operational: create teams and assign players — depends on this code fix)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
forgejo_admin/basketball-api#121
No description provided.