This commit is contained in:
Phuoc Nguyen
2025-11-03 15:02:33 +07:00
parent 56c470baa1
commit aa3a52bba7
17 changed files with 1393 additions and 345 deletions

View File

@@ -0,0 +1,55 @@
/// Notification Repository Implementation
///
/// Concrete implementation of NotificationRepository.
/// Coordinates between local datasource and domain layer.
library;
import 'package:worker/features/notifications/data/datasources/notification_local_datasource.dart';
import 'package:worker/features/notifications/data/models/notification_model.dart';
import 'package:worker/features/notifications/domain/entities/notification.dart';
import 'package:worker/features/notifications/domain/repositories/notification_repository.dart';
/// Notification Repository Implementation
class NotificationRepositoryImpl implements NotificationRepository {
/// Local data source
final NotificationLocalDataSource localDataSource;
/// Constructor
NotificationRepositoryImpl({required this.localDataSource});
@override
Future<List<Notification>> getAllNotifications() async {
final jsonList = await localDataSource.getAllNotifications();
return jsonList.map((json) => NotificationModel.fromJson(json)).toList()
..sort((a, b) => b.createdAt.compareTo(a.createdAt)); // Sort by newest first
}
@override
Future<List<Notification>> getNotificationsByCategory(String category) async {
final jsonList = await localDataSource.getNotificationsByCategory(category);
return jsonList.map((json) => NotificationModel.fromJson(json)).toList()
..sort((a, b) => b.createdAt.compareTo(a.createdAt));
}
@override
Future<int> getUnreadCount() async {
return await localDataSource.getUnreadCount();
}
@override
Future<void> markAsRead(String notificationId) async {
await localDataSource.markAsRead(notificationId);
}
@override
Future<void> markAllAsRead() async {
await localDataSource.markAllAsRead();
}
@override
Future<List<Notification>> refreshNotifications() async {
// For now, just fetch all notifications
// In production, this would fetch from server
return await getAllNotifications();
}
}