feat: intern batch self-selection endpoint and service
Description
Allow interns to self-select their batch on first login via a one-time onboarding
screen. Previously, users.batch_id was always NULL after Corpus login, forcing
admins to manually assign every intern. Now interns pick their batch immediately
after logging in for the first time.
Related Issue
Closes #1
Type of Change
-
New feature (non-breaking change which adds functionality) -
Bug fix (non-breaking change which fixes an issue) -
Breaking change (fix or feature that would cause existing functionality to not work as expected) -
Documentation update
Changes Made
Backend (intern-activity-tracker)
| File | Change |
|---|---|
app/routers/me.py |
Added PATCH /api/me/batch endpoint for one-time batch self-assignment |
app/routers/batches.py |
Relaxed GET /api/batches/ to allow interns to list batches (returns id + name only; count fields are null) |
src/.../services/roster_service.py |
Added assign_user_batch() — enforces one-time-only batch assignment |
app/schemas/roster.py |
Changed BatchResponse count fields from int = 0 to Optional[int] = None
|
tests/test_roster_service.py |
4 new tests: success, already-set, nonexistent-batch, nonexistent-user |
API Contract
PATCH /api/me/batch
Request:
{ "batch_id": 1 }
Responses:
-
200— Updated profile withbatch_idset -
400— Batch not found or does not exist -
409— Batch already set (one-time choice only)
How It Works
- Intern logs in via Corpus →
batch_idisNULL - Frontend calls
GET /api/batches/→ returns batchid+name(counts arenull) - Intern picks a batch → frontend calls
PATCH /api/me/batch - Backend validates: batch exists? not already set? → updates
users.batch_id - Intern is redirected to the main app with their batch set
How Has This Been Tested?
-
Unit tests pass: 4 new tests, 20 total in test_roster_service.py -
ruff check .— All checks passed -
mypy— Success: no issues found in 51 source files -
Manual testing in Swagger UI ( /docs)
Screenshots (if appropriate)
N/A — backend-only changes. See companion MR in team_standup_tracker for frontend screenshots.
Checklist
-
My code follows the project's coding conventions -
I have performed a self-review of my own code -
I have commented my code where necessary -
I have made corresponding changes to the documentation -
My changes generate no new warnings -
I have added tests that prove my fix/feature works -
New and existing unit tests pass locally
Companion MR
-
Frontend:
team_standup_tracker→ MR title:feat: intern batch self-selection onboarding screen -
Branch:
feat/intern-batch-self-selectionin both repos
Semantic Versioning Impact
-
Patch -
Minor -
Major
Reviewer Notes
- The
assign_user_batch()service function has a double-guard: the endpoint checksbatch_idbefore calling the service, and the service checks again inside a transaction. This prevents race conditions from concurrent requests. -
BatchResponsecount fields (team_count,member_count) were changed fromint = 0toOptional[int] = None. This means the frontend should handlenullvalues for interns. Mentors/admins will still receive actual integers.
Edited by Praneeth Ashish