Solian/lib/models/notification.dart

80 lines
2.0 KiB
Dart
Raw Normal View History

2024-04-13 11:47:31 +00:00
class Notification {
int id;
DateTime createdAt;
DateTime updatedAt;
DateTime? deletedAt;
String subject;
String content;
List<Link>? links;
bool isImportant;
2024-04-24 15:19:26 +00:00
bool isRealtime;
2024-04-13 11:47:31 +00:00
DateTime? readAt;
2024-05-05 15:01:08 +00:00
int? senderId;
2024-04-13 11:47:31 +00:00
int recipientId;
Notification({
required this.id,
required this.createdAt,
required this.updatedAt,
this.deletedAt,
required this.subject,
required this.content,
this.links,
required this.isImportant,
2024-04-24 15:19:26 +00:00
required this.isRealtime,
2024-04-13 11:47:31 +00:00
this.readAt,
2024-05-05 15:01:08 +00:00
this.senderId,
2024-04-13 11:47:31 +00:00
required this.recipientId,
});
factory Notification.fromJson(Map<String, dynamic> json) => Notification(
2024-05-01 16:49:38 +00:00
id: json['id'],
createdAt: DateTime.parse(json['created_at']),
updatedAt: DateTime.parse(json['updated_at']),
deletedAt: json['deleted_at'],
subject: json['subject'],
content: json['content'],
2024-05-05 15:01:08 +00:00
links: json['links'] != null ? List<Link>.from(json['links'].map((x) => Link.fromJson(x))) : List.empty(),
2024-05-01 16:49:38 +00:00
isImportant: json['is_important'],
isRealtime: json['is_realtime'],
readAt: json['read_at'],
senderId: json['sender_id'],
recipientId: json['recipient_id'],
2024-04-13 11:47:31 +00:00
);
Map<String, dynamic> toJson() => {
2024-05-01 16:49:38 +00:00
'id': id,
'created_at': createdAt.toIso8601String(),
'updated_at': updatedAt.toIso8601String(),
'deleted_at': deletedAt,
'subject': subject,
'content': content,
2024-05-05 15:01:08 +00:00
'links': links != null ? List<dynamic>.from(links!.map((x) => x.toJson())) : List.empty(),
2024-05-01 16:49:38 +00:00
'is_important': isImportant,
'is_realtime': isRealtime,
'read_at': readAt,
'sender_id': senderId,
'recipient_id': recipientId,
2024-04-13 11:47:31 +00:00
};
}
class Link {
String label;
String url;
Link({
required this.label,
required this.url,
});
factory Link.fromJson(Map<String, dynamic> json) => Link(
2024-05-01 16:49:38 +00:00
label: json['label'],
url: json['url'],
2024-04-13 11:47:31 +00:00
);
Map<String, dynamic> toJson() => {
2024-05-01 16:49:38 +00:00
'label': label,
'url': url,
2024-04-13 11:47:31 +00:00
};
}