3.0 KiB
3.0 KiB
ParentPromotionController plan
Scope
- Controller:
app/Http/Controllers/Api/Parents/ParentPromotionController.php - Purpose: parent portal endpoints for promotion + enrollment workflow.
- Primary dependencies:
App\Services\Promotions\PromotionEnrollmentServiceApp\Services\Promotions\PromotionQueryService
- Models:
App\Models\StudentPromotionRecordApp\Models\Student(ownership verification fallback)
Routes
All routes are under v1 + parents group:
- Base prefix:
... /api/v1/parents/promotions - Group middleware:
parent.access
Endpoints:
GET /api/v1/parents/promotions/→overviewGET /api/v1/parents/promotions/{promotionId}→showPOST /api/v1/parents/promotions/{promotionId}/start→startPATCH /api/v1/parents/promotions/{promotionId}/steps→updateStepsPOST /api/v1/parents/promotions/{promotionId}/submit→submit
Authentication & authorization
- Parent context resolved via
parentIdOrUnauthorized():- prefers request attribute
primary_parent_id(set byparent.access) - falls back to
auth()->id()
- prefers request attribute
- Ownership is enforced in
loadOwnedRecord():- Primary check:
StudentPromotionRecord.parent_id == parentId - Fallback: loads
Student.parent_idfor the record’sstudent_id - If not owned: returns
403{ ok:false, message:"You are not authorised..." }
- Primary check:
Requests/validation
overview:ParentPromotionOverviewRequest(optionalnext_school_year)updateSteps:ParentEnrollmentStepRequest(steps()accessor provides structured step payload)
Response shapes
overview:{ ok:true, records, next_school_year, message }- Note:
recordsare returned as provided byPromotionEnrollmentService::overviewForParent(...)(already shaped for the client)
show/start/updateSteps/submit:{ ok:true, data: StudentPromotionResource(...) }
State transitions (high-level)
start→PromotionEnrollmentService::startEnrollment(...)updateSteps→PromotionEnrollmentService::updateSteps(...)submit→PromotionEnrollmentService::submitEnrollment(...)- Conflicts (invalid transition / deadline / status) surface as
409with{ ok:false, message }.
Error handling expectations
- Unauthorized →
401{ ok:false, message:"Unauthorized." } - Record not found →
404{ ok:false, message:"Promotion record not found." } - Not owned →
403{ ok:false, message:"You are not authorised..." } - Invalid transition →
409{ ok:false, message }
Test plan (feature)
- Ownership:
- Parent cannot access another parent’s record (403).
- Record with mismatched
parent_idbut student belongs to parent passes ownership check.
- Happy path:
overviewreturns list for parent.startmoves record to started state and returns updated resource.updateStepspersists steps and returns updated resource.submittransitions to submitted state.
- Conflict cases:
- Submitting without required steps → 409.
- Past deadline → 409 (as enforced by service).