Files
social-app/apps/lib/data/repositories/models/calendar_event.dart
T

41 lines
1.0 KiB
Dart
Raw Normal View History

enum CalendarEventStatus { active, archived }
class CalendarEvent {
final String id;
final String title;
final DateTime startAt;
final DateTime? endAt;
final CalendarEventStatus status;
const CalendarEvent({
required this.id,
required this.title,
required this.startAt,
required this.endAt,
required this.status,
});
factory CalendarEvent.fromJson(Map<String, dynamic> json) {
return CalendarEvent(
id: json['id'] as String,
title: json['title'] as String,
startAt: DateTime.parse(json['start_at'] as String).toLocal(),
endAt: json['end_at'] == null
? null
: DateTime.parse(json['end_at'] as String).toLocal(),
status: _calendarEventStatusFromApi(json['status'] as String),
);
}
}
CalendarEventStatus _calendarEventStatusFromApi(String raw) {
switch (raw) {
case 'active':
return CalendarEventStatus.active;
case 'archived':
return CalendarEventStatus.archived;
default:
throw StateError('Unsupported calendar event status: $raw');
}
}