Build Dart repository class for certification status
epic-peer-mentor-pause-management-foundation-task-003 — Implement the CertificationStatusRepository Dart class with methods to query, insert, update, and stream certification records from Supabase. Include typed data models, error handling, and Riverpod provider registration.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 2 - 518 tasks
Can start after Tier 1 completes
Implementation Notes
Follow the repository pattern already established in the codebase — look at existing repositories (e.g., PeerMentorStatusRepository if it exists) for the constructor signature, provider registration pattern, and error wrapping convention. Use freezed for CertificationStatus if the rest of the project uses it — consistency matters more than personal preference. For the Realtime stream, use supabase.from('cert_expiry_reminders').stream(primaryKey: ['id']).eq('mentor_id', mentorId) which returns a Stream>> that you map to Stream
>. Remember to cancel the subscription in a dispose method or use Riverpod's ref.onDispose.
The upsert should use onConflict: 'mentor_id,certification_type' to match the unique constraint defined in the schema migration.
Testing Requirements
Unit tests using flutter_test with a mocked SupabaseClient (mockito or mocktail). Test: (1) fetchForMentor returns a typed List
Supabase RLS policies for coordinator-scoped status queries may be difficult to express correctly, especially for peer mentors assigned to multiple coordinators or chapters, leading to data leakage or overly restrictive access blocking valid queries.
Mitigation & Contingency
Mitigation: Design RLS policies using security-definer RPCs rather than table-level policies for complex multi-coordinator scenarios. Write a comprehensive RLS test matrix covering all role and assignment permutations before marking complete.
Contingency: Fall back to application-level filtering in the repository layer with explicit coordinator_id parameter checks if RLS proves intractable, and document the trade-off for security review.
The HLF Dynamics portal API contract may be undocumented or subject to change, causing the DynamicsPortalClient to break during development or production rollout.
Mitigation & Contingency
Mitigation: Obtain the full Dynamics portal API specification and credentials early in the sprint. Build the client behind a well-defined interface so the HLF-specific implementation can be swapped without affecting upstream services.
Contingency: If the Dynamics API is unavailable or unstable, stub the client with a feature-flag-guarded no-op implementation so all other epics can proceed to completion independently.
Supabase Edge Functions used as the nightly scheduler host may have cold-start latency or execution time limits that prevent reliable nightly certification checks on large mentor rosters.
Mitigation & Contingency
Mitigation: Benchmark Edge Function execution time against the expected roster size. Design the expiry check to process in paginated batches to stay within execution limits. Use pg_cron with a direct database function as an alternative trigger if Edge Functions prove unreliable.
Contingency: Migrate the scheduler trigger to pg_cron invoking a Postgres function directly, removing the Edge Function dependency entirely for the scheduling layer.