46 lines
1.5 KiB
Dart
46 lines
1.5 KiB
Dart
/// Notification Model
|
|
///
|
|
/// Converts JSON data from API to domain entity.
|
|
library;
|
|
|
|
import 'package:worker/features/notifications/domain/entities/notification.dart';
|
|
|
|
/// Notification Model
|
|
///
|
|
/// Handles JSON serialization/deserialization.
|
|
class NotificationModel {
|
|
/// Convert JSON to Notification entity
|
|
static Notification fromJson(Map<String, dynamic> json) {
|
|
return Notification(
|
|
notificationId: json['notification_id'] as String,
|
|
userId: json['user_id'] as String,
|
|
type: json['type'] as String,
|
|
title: json['title'] as String,
|
|
message: json['message'] as String,
|
|
data: json['data'] as Map<String, dynamic>?,
|
|
isRead: json['is_read'] as bool? ?? false,
|
|
isPushed: json['is_pushed'] as bool? ?? false,
|
|
createdAt: DateTime.parse(json['created_at'] as String),
|
|
readAt: json['read_at'] != null
|
|
? DateTime.parse(json['read_at'] as String)
|
|
: null,
|
|
);
|
|
}
|
|
|
|
/// Convert Notification entity to JSON
|
|
static Map<String, dynamic> toJson(Notification notification) {
|
|
return {
|
|
'notification_id': notification.notificationId,
|
|
'user_id': notification.userId,
|
|
'type': notification.type,
|
|
'title': notification.title,
|
|
'message': notification.message,
|
|
'data': notification.data,
|
|
'is_read': notification.isRead,
|
|
'is_pushed': notification.isPushed,
|
|
'created_at': notification.createdAt.toIso8601String(),
|
|
'read_at': notification.readAt?.toIso8601String(),
|
|
};
|
|
}
|
|
}
|