71 lines
1.8 KiB
Dart
71 lines
1.8 KiB
Dart
import '../utils/app_time.dart';
|
|
|
|
class Announcement {
|
|
Announcement({
|
|
required this.id,
|
|
required this.authorId,
|
|
required this.title,
|
|
required this.body,
|
|
required this.visibleRoles,
|
|
required this.isTemplate,
|
|
this.templateId,
|
|
required this.createdAt,
|
|
required this.updatedAt,
|
|
});
|
|
|
|
final String id;
|
|
final String authorId;
|
|
final String title;
|
|
final String body;
|
|
final List<String> visibleRoles;
|
|
final bool isTemplate;
|
|
final String? templateId;
|
|
final DateTime createdAt;
|
|
final DateTime updatedAt;
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
identical(this, other) ||
|
|
other is Announcement &&
|
|
runtimeType == other.runtimeType &&
|
|
id == other.id &&
|
|
authorId == other.authorId &&
|
|
title == other.title &&
|
|
body == other.body &&
|
|
isTemplate == other.isTemplate &&
|
|
templateId == other.templateId &&
|
|
createdAt == other.createdAt &&
|
|
updatedAt == other.updatedAt;
|
|
|
|
@override
|
|
int get hashCode => Object.hash(
|
|
id,
|
|
authorId,
|
|
title,
|
|
body,
|
|
isTemplate,
|
|
templateId,
|
|
createdAt,
|
|
updatedAt,
|
|
);
|
|
|
|
factory Announcement.fromMap(Map<String, dynamic> map) {
|
|
final rolesRaw = map['visible_roles'];
|
|
final roles = rolesRaw is List
|
|
? rolesRaw.cast<String>()
|
|
: <String>[];
|
|
|
|
return Announcement(
|
|
id: map['id'] as String,
|
|
authorId: map['author_id'] as String,
|
|
title: map['title'] as String? ?? '',
|
|
body: map['body'] as String? ?? '',
|
|
visibleRoles: roles,
|
|
isTemplate: map['is_template'] as bool? ?? false,
|
|
templateId: map['template_id'] as String?,
|
|
createdAt: AppTime.parse(map['created_at'] as String),
|
|
updatedAt: AppTime.parse(map['updated_at'] as String),
|
|
);
|
|
}
|
|
}
|