Feature: Admin Notification API for Camp Volunteers
Description
Implement a backend endpoint that allows administrators to broadcast updates to volunteers signed up for the upcoming medical camp via email and/or push notifications.
Technical Requirements
-
Endpoint:
POST /api/v1/admin/notifications/broadcast(Admin role guarded). -
Request Payload:
{ "title": "string", "message": "string", "send_email": boolean, "send_push": boolean }
Logic
- Filter users where
role == 'volunteer'and they are actively signed up for the current camp. - Use FastAPI
BackgroundTasksto handle bulk execution asynchronously to avoid API timeouts. - Integrate with the existing mailing system for email delivery.
- Integrate a push notification service (e.g., Firebase Admin SDK) using stored device tokens (e.g.,
fcm_tokenon the user model).
Test Cases (Backend Validation)
-
TC-BE-01 (Unauthorized Access): Verify that requests from non-admin roles (e.g., regular volunteers or unauthenticated requests) return a 403 Forbiddenor401 Unauthorizedstatus code. -
TC-BE-02 (Payload Validation): Verify that submitting an empty titleormessagereturns a422 Unprocessable Entityerror. -
TC-BE-03 (Target Filtering): Mock a database setup with 3 users: (A) Signed-up volunteer, (B) Non-signed-up volunteer, and (C) Doctor. Verify that only user (A) is fetched in the broadcast query loop. -
TC-BE-04 (Async Execution): Verify that the endpoint returns a 202 Acceptedresponse instantly, before the simulated bulk email/push functions finish running in the background. -
TC-BE-05 (Channel Toggles): Verify that if send_emailis false andsend_pushis true, the mailing service task is completely skipped and only the push gateway is invoked.
Acceptance Criteria
-
Endpoint securely validates admin credentials. -
API successfully filters only camp-enrolled volunteers. -
API processes sending in the background and returns a quick response.
Edited by Rajasekhar Ponakala