Notifications
Push notification history and FCM token management.
Register FCM Token
POST /teacher/notification/token
{
"data": {
"fcmToken": "..."
}
}
Called on app start to register the device for push notifications.
Get Delivered Notifications
GET /teacher/notification/delivered-notifications
{
"data": {
"notifications": [
{
"id": "uuid",
"title": "New Leave Request",
"body": "John Doe has applied for leave on 15th April",
"type": "LEAVE_REQUEST",
"readAt": null,
"createdAt": "2024-04-01T08:00:00Z"
}
]
}
}
Mark as Read
POST /teacher/notification/read
{
"data": {
"notificationId": "uuid"
}
}
FCM Topics
Teachers are subscribed to topic-based notifications:
| Topic | Purpose |
|---|---|
school_{id} | School-wide announcements |
teacher_{id} | Direct notifications |
await FirebaseMessaging.instance.subscribeToTopic('school_$schoolId');
await FirebaseMessaging.instance.subscribeToTopic('teacher_$teacherId');
Notification Tap Handling
FirebaseMessaging.onMessageOpenedApp.listen((message) {
final data = message.data;
switch (data['type']) {
case 'LEAVE_REQUEST':
Navigator.pushNamed(context, '/student-leave');
break;
case 'ANNOUNCEMENT':
Navigator.pushNamed(context, '/announcements/${data['id']}');
break;
}
});