Notification System Overview
This document provides an overview of the notification system for client developers integrating with the backend. It explains notification types, expected payloads, and device token registration.
Notification Types
Notifications sent to clients are categorized by NotificationType:
- TREND: Informs users about changes in their mobility trends (e.g., reduced car usage). See
TrendNotificationService. - ADHOC_ALTERNATIVE: Suggests a more sustainable alternative after a recent trip upload. See
AdHocSuggestionService. - REGULAR_TRIP_ALTERNATIVE: Suggests an alternative for a detected regular trip (e.g., weekly commute). See
RegularTripSuggestionService. - FRIENDSHIP_REQUEST_RECEIVED: Notifies about a new pending friendship request.
See NotificationType.java for the full enum.
Notification Payloads
Each notification type includes a data payload. The main DTOs in the notification body are:
- TREND: Contains a list of
TrendDetectionDTOobjects, each describing a detected trend for the user. The structure includes fields such asuserId,timespan,type,attribute,deltaType,changeValue, andtrendConnotation. SeeTrendDetectionDTO.javafor details. - ADHOC_ALTERNATIVE: Contains a list of
RouteDTOobjects representing the best alternative(s) for a recent trip ( seeAdHocSuggestionService). - REGULAR_TRIP_ALTERNATIVE: Contains a list of 1 or 2
RouteDTOobjects for the best alternative(s) to a detected regular trip, depending on user preferences (e.g., ifpreferPhysicalActivityis set, two alternatives may be included). SeeRegularTripSuggestionServiceandRegularTripDetectionServicefor details. - FRIENDSHIP_REQUEST_RECEIVED: Contains a
friendshipDTOwherefriendis the user who sent the request. SeeFriendshipDTO.java.
Device Token Registration
To receive push notifications, clients must register their device token. Token registration is handled in the
NotificationController. The backend stores or updates the token for the authenticated user.
Unregistering Device Token
When a user logs out, the client should call the device token unregistration endpoint to remove the device token from the backend. This ensures the user will no longer receive push notifications on that device after logout.
- Endpoint:
PUT /notifications/unregister-device-token
For Backend Developers
To queue notifications for users, use the NotificationSchedulerService as the main entry point. This service provides
methods to schedule notifications with the appropriate type and payload. See NotificationSchedulerService.java for
usage details.
For further details, refer to the respective service and DTO classes in the codebase.