2024-05-18 10:17:16 +00:00
|
|
|
class Notification {
|
|
|
|
int id;
|
|
|
|
DateTime createdAt;
|
|
|
|
DateTime updatedAt;
|
|
|
|
DateTime? deletedAt;
|
|
|
|
String subject;
|
|
|
|
String content;
|
|
|
|
List<Link>? links;
|
|
|
|
bool isImportant;
|
|
|
|
bool isRealtime;
|
|
|
|
DateTime? readAt;
|
|
|
|
int? senderId;
|
|
|
|
int recipientId;
|
|
|
|
|
|
|
|
Notification({
|
|
|
|
required this.id,
|
|
|
|
required this.createdAt,
|
|
|
|
required this.updatedAt,
|
2024-05-28 16:14:41 +00:00
|
|
|
required this.deletedAt,
|
2024-05-18 10:17:16 +00:00
|
|
|
required this.subject,
|
|
|
|
required this.content,
|
2024-05-28 16:14:41 +00:00
|
|
|
required this.links,
|
2024-05-18 10:17:16 +00:00
|
|
|
required this.isImportant,
|
|
|
|
required this.isRealtime,
|
2024-05-28 16:14:41 +00:00
|
|
|
required this.readAt,
|
|
|
|
required this.senderId,
|
2024-05-18 10:17:16 +00:00
|
|
|
required this.recipientId,
|
|
|
|
});
|
|
|
|
|
|
|
|
factory Notification.fromJson(Map<String, dynamic> json) => Notification(
|
|
|
|
id: json['id'] ?? 0,
|
2024-05-28 16:14:41 +00:00
|
|
|
createdAt: json['created_at'] == null
|
|
|
|
? DateTime.now()
|
|
|
|
: DateTime.parse(json['created_at']),
|
|
|
|
updatedAt: json['updated_at'] == null
|
|
|
|
? DateTime.now()
|
|
|
|
: DateTime.parse(json['updated_at']),
|
2024-05-18 10:17:16 +00:00
|
|
|
deletedAt: json['deleted_at'],
|
|
|
|
subject: json['subject'],
|
|
|
|
content: json['content'],
|
2024-05-28 16:14:41 +00:00
|
|
|
links: json['links'] != null
|
|
|
|
? List<Link>.from(json['links'].map((x) => Link.fromJson(x)))
|
|
|
|
: List.empty(),
|
2024-05-18 10:17:16 +00:00
|
|
|
isImportant: json['is_important'],
|
|
|
|
isRealtime: json['is_realtime'],
|
|
|
|
readAt: json['read_at'],
|
|
|
|
senderId: json['sender_id'],
|
|
|
|
recipientId: json['recipient_id'],
|
|
|
|
);
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
|
|
'id': id,
|
|
|
|
'created_at': createdAt.toIso8601String(),
|
|
|
|
'updated_at': updatedAt.toIso8601String(),
|
|
|
|
'deleted_at': deletedAt,
|
|
|
|
'subject': subject,
|
|
|
|
'content': content,
|
2024-05-28 16:14:41 +00:00
|
|
|
'links': links != null
|
|
|
|
? List<dynamic>.from(links!.map((x) => x.toJson()))
|
|
|
|
: List.empty(),
|
2024-05-18 10:17:16 +00:00
|
|
|
'is_important': isImportant,
|
|
|
|
'is_realtime': isRealtime,
|
|
|
|
'read_at': readAt,
|
|
|
|
'sender_id': senderId,
|
|
|
|
'recipient_id': recipientId,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
class Link {
|
|
|
|
String label;
|
|
|
|
String url;
|
|
|
|
|
|
|
|
Link({
|
|
|
|
required this.label,
|
|
|
|
required this.url,
|
|
|
|
});
|
|
|
|
|
|
|
|
factory Link.fromJson(Map<String, dynamic> json) => Link(
|
|
|
|
label: json['label'],
|
|
|
|
url: json['url'],
|
|
|
|
);
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
|
|
'label': label,
|
|
|
|
'url': url,
|
|
|
|
};
|
|
|
|
}
|