diff --git a/lib/data/repositories/notification_repository.dart b/lib/data/repositories/notification_repository.dart index fc0075c..4a0db4f 100644 --- a/lib/data/repositories/notification_repository.dart +++ b/lib/data/repositories/notification_repository.dart @@ -1,3 +1,4 @@ +// notification_repository.dart import 'package:tm_app/core/utils/result.dart'; import 'package:tm_app/data/services/model/notification__response/notification_response_model.dart'; import 'package:tm_app/data/services/notification_service.dart'; @@ -28,4 +29,14 @@ class NotificationsRepository { offset: offset, ); } + + Future> getImportantNotifications({ + required int limit, + required int offset, + }) { + return _notificationsService.getImportantNotifications( + limit: limit, + offset: offset, + ); + } } diff --git a/lib/data/services/api/notification_api.dart b/lib/data/services/api/notification_api.dart index a2d0af3..07c4d57 100644 --- a/lib/data/services/api/notification_api.dart +++ b/lib/data/services/api/notification_api.dart @@ -1,17 +1,19 @@ +// notification_api.dart class NotificationApi { static const String notifications = '/api/v1/notifications'; static String getNotifications({required int limit, required int offset}) { return '$notifications?limit=$limit&offset=$offset'; } - static const String feedback = '/api/v1/feedback'; - - static const String markAllAsRead = '/api/v1/notifications/mark'; static const String markAsRead = '/api/v1/notifications/mark-as-read'; - static const String tenderApprovalsTender = '/api/v1/notifications'; + static const String unreadNotifications = '/api/v1/notifications?seen=false'; - static String getUnreadNotifications({required int limit, required int offset}) { - return '$unreadNotifications?limit=$limit&offset=$offset'; + static String getUnreadNotifications({required int limit, required int offset}) { + return '/api/v1/notifications?seen=false&limit=$limit&offset=$offset'; } -} + + static String getImportantNotifications({required int limit, required int offset}) { + return '/api/v1/notifications?priority=important&limit=$limit&offset=$offset'; + } +} \ No newline at end of file diff --git a/lib/data/services/notification_service.dart b/lib/data/services/notification_service.dart index 45e0b25..14eab95 100644 --- a/lib/data/services/notification_service.dart +++ b/lib/data/services/notification_service.dart @@ -1,10 +1,8 @@ // notification_service.dart import 'dart:convert'; - import 'package:tm_app/core/utils/result.dart'; import 'package:tm_app/data/services/api/notification_api.dart'; import 'package:tm_app/data/services/model/notification__response/notification_response_model.dart'; - import '../../core/network/network_manager.dart'; class NotificationsService { @@ -18,7 +16,6 @@ class NotificationsService { }) async { final result = await _networkManager.makeRequest( NotificationApi.getNotifications(limit: limit, offset: offset), - //NotificationApi.notifications, method: 'GET', (json) => NotificationResponseModel.fromJson(json), ); @@ -52,7 +49,19 @@ class NotificationsService { required int offset, }) async { final result = await _networkManager.makeRequest( - NotificationApi.unreadNotifications, + NotificationApi.getUnreadNotifications(limit: limit, offset: offset), + method: 'GET', + (json) => NotificationResponseModel.fromJson(json), + ); + return result; + } + + Future> getImportantNotifications({ + required int limit, + required int offset, + }) async { + final result = await _networkManager.makeRequest( + NotificationApi.getImportantNotifications(limit: limit, offset: offset), method: 'GET', (json) => NotificationResponseModel.fromJson(json), ); diff --git a/lib/view_models/notification_view_model.dart b/lib/view_models/notification_view_model.dart index 43bdf17..db48bbb 100644 --- a/lib/view_models/notification_view_model.dart +++ b/lib/view_models/notification_view_model.dart @@ -1,3 +1,4 @@ +// notification_view_model.dart import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:tm_app/core/utils/app_toast.dart'; @@ -169,7 +170,7 @@ class NotificationViewModel with ChangeNotifier { final int offset = (page - 1) * _pageSize; - final result = await _repository.getUnreadNotifications( + final result = await _repository.getImportantNotifications( limit: _pageSize, offset: offset, ); diff --git a/lib/views/notification/widgets/notification_important_tab.dart b/lib/views/notification/widgets/notification_important_tab.dart index cc00dbe..9d5e417 100644 --- a/lib/views/notification/widgets/notification_important_tab.dart +++ b/lib/views/notification/widgets/notification_important_tab.dart @@ -17,15 +17,7 @@ class NotificationImportantTab extends StatelessWidget { return const Center(child: CircularProgressIndicator()); } - final importantFromApi = viewModel.importantNotificationResponse?.data ?? []; - - final allNotifications = viewModel.allNotificationResponse?.data ?? []; - - final source = importantFromApi.isNotEmpty ? importantFromApi : allNotifications; - - final importantNotifications = source - .where((n) => (n.priority ?? '').toLowerCase() == 'important') - .toList(); + final importantNotifications = viewModel.importantNotificationResponse?.data ?? []; if (importantNotifications.isEmpty) { return const Center(child: Text(NotificationStrings.noImportantNotifications));