Service Layer medium complexity frontendmobile
5
Dependencies
0
Dependents
2
Entities
0
Integrations

Description

Orchestrates parallel fetching and merging of data from multiple sources (profile, certification, activity log, assignment history) into the unified PeerMentorDetailModel consumed by the BLoC. Reduces coupling between the BLoC and individual repositories.

Feature: Peer Mentor Profile & Status Screen

peer-mentor-aggregation-service

Summaries

The Peer Mentor Profile Aggregation Service is the backbone of the mentor detail experience, ensuring that administrators and users always see a complete, accurate picture of each mentor regardless of how data is distributed across backend systems. By fetching all relevant data in parallel, it minimizes screen load times, directly improving user satisfaction and mentor profile engagement. Organization-specific filtering ensures that sensitive HLF certification data and Blindeforbundet assignment details are only surfaced to authorized contexts, reducing compliance exposure. This service's resilience to partial failures means mentor profiles remain usable even during backend disruptions.

Medium complexity with dependencies on four repositories plus the certification status service. All five dependencies must be integration-ready before end-to-end testing of this service is possible. The parallel fetch design using Future.wait reduces perceived latency but requires careful testing of timeout and partial failure scenarios. Allocate dedicated QA time for organization-specific filtering logic — HLF and Blindeforbundet rules must each be verified with representative test data.

Because this service decouples the BLoC from individual repositories, changes to any single repository interface are isolated here, reducing regression surface across the feature. No backend deployment required.

Orchestrates Future.wait over four parallel repository calls (profile, certification, activity log, assignments) with per-source fallback via fetchWithFallback(). The merge() method accepts the four resolved models and delegates status derivation to CertificationStatusService before constructing the final PeerMentorDetailModel. Organization-specific filtering is applied post-merge: HLF certification fields are included only when orgId matches HLF tenants; assignment history is scoped to Blindeforbundet org context. Errors from individual futures are caught inside fetchWithFallback, returning the provided fallback value so merge() always receives a complete argument list.

This pattern keeps the BLoC's error handling limited to whole-model failures rather than per-field nullability.

Responsibilities

  • Fetch peer mentor profile, certification, and activity data in parallel using Future.wait
  • Merge results into a single PeerMentorDetailModel
  • Apply organization-specific data filtering (HLF certification, Blindeforbundet assignments)
  • Propagate per-source errors without failing the entire aggregation

Interfaces

fetchMentorDetail({required String mentorId, required String organizationId})
PeerMentorDetailModel merge(PeerMentorProfile, CertificationRecord?, MentorActivitySummary, List<AssignedContact>)
fetchWithFallback<T>(Future<T> fetch, T fallback)

Related Data Entities (2)

Data entities managed by this component

API Contract

View full contract →
REST /api/v1/peer-mentor-details 5 endpoints
GET /api/v1/peer-mentor-details List aggregated mentor detail models for an organization
GET /api/v1/peer-mentor-details/:id Get full aggregated mentor detail (profile + certification + activity + assignments)
POST /api/v1/peer-mentor-details Create mentor profile (delegates to peer-mentor-repository)
PUT /api/v1/peer-mentor-details/:id Update mentor profile fields
DELETE /api/v1/peer-mentor-details/:id Remove mentor and cascade-close open assignments