1
1
import 'dart:typed_data' ;
2
2
3
- import 'package:freezed_annotation/freezed_annotation .dart' ;
3
+ import 'package:dart_mappable/dart_mappable .dart' ;
4
4
5
- import '../../../helpers/converter.dart' ;
6
5
import '../../model.dart' ;
7
6
import '../model.dart' ;
8
7
9
- part 'model.freezed.dart' ;
10
- part 'model.g.dart' ;
8
+ part 'model.mapper.dart' ;
11
9
10
+ @MappableEnum ()
12
11
enum CalendarItemType { appointment, moment, pending }
13
12
14
- @freezed
15
- class CalendarItem
16
- with _$CalendarItem , IdentifiedModel , NamedModel , DescriptiveModel {
17
- const CalendarItem ._();
13
+ @MappableClass ()
14
+ sealed class CalendarItem
15
+ with CalendarItemMappable , IdentifiedModel , NamedModel , DescriptiveModel {
16
+ @override
17
+ final Uint8List ? id;
18
+ @override
19
+ final String name, description;
20
+ final String location;
21
+ final Uint8List ? groupId, placeId, eventId;
22
+ final DateTime ? start, end;
23
+ final EventStatus status;
18
24
19
- const factory CalendarItem .fixed ({
20
- @Uint 8ListConverter () Uint8List ? id,
21
- @Default ('' ) String name,
22
- @Default ('' ) String description,
23
- @Default ('' ) String location,
24
- @Uint 8ListConverter () Uint8List ? groupId,
25
- @Uint 8ListConverter () Uint8List ? placeId,
26
- @Uint 8ListConverter () Uint8List ? eventId,
27
- @Default (EventStatus .confirmed) EventStatus status,
28
- @DateTimeConverter () DateTime ? start,
29
- @DateTimeConverter () DateTime ? end,
30
- }) = FixedCalendarItem ;
31
-
32
- const factory CalendarItem .repeating ({
33
- @Uint 8ListConverter () Uint8List ? id,
34
- @Default ('' ) String name,
35
- @Default ('' ) String description,
36
- @Default ('' ) String location,
37
- @Uint 8ListConverter () Uint8List ? groupId,
38
- @Uint 8ListConverter () Uint8List ? placeId,
39
- @Uint 8ListConverter () Uint8List ? eventId,
40
- @Default (EventStatus .confirmed) EventStatus status,
41
- @DateTimeConverter () DateTime ? start,
42
- @DateTimeConverter () DateTime ? end,
43
- @Default (RepeatType .daily) RepeatType repeatType,
44
- @Default (1 ) int interval,
45
- @Default (0 ) int variation,
46
- @Default (0 ) int count,
47
- @DateTimeConverter () DateTime ? until,
48
- @Default ([]) List <int > exceptions,
49
- }) = RepeatingCalendarItem ;
50
-
51
- const factory CalendarItem .auto ({
52
- @Uint 8ListConverter () Uint8List ? id,
53
- @Default ('' ) String name,
54
- @Default ('' ) String description,
55
- @Default ('' ) String location,
56
- @Uint 8ListConverter () Uint8List ? groupId,
57
- @Uint 8ListConverter () Uint8List ? placeId,
58
- @Uint 8ListConverter () Uint8List ? eventId,
59
- @Default (EventStatus .confirmed) EventStatus status,
60
- @DateTimeConverter () DateTime ? start,
61
- @DateTimeConverter () DateTime ? end,
62
- @Uint 8ListConverter () Uint8List ? autoGroupId,
63
- @DateTimeConverter () DateTime ? searchStart,
64
- @Default (60 ) int autoDuration,
65
- }) = AutoCalendarItem ;
66
-
67
- factory CalendarItem .fromJson (Map <String , dynamic > json) =>
68
- _$CalendarItemFromJson (json);
25
+ const CalendarItem ({
26
+ this .id,
27
+ this .name = '' ,
28
+ this .description = '' ,
29
+ this .location = '' ,
30
+ this .groupId,
31
+ this .placeId,
32
+ this .eventId,
33
+ this .start,
34
+ this .end,
35
+ this .status = EventStatus .confirmed,
36
+ });
69
37
70
38
factory CalendarItem .fromDatabase (Map <String , dynamic > row) =>
71
- CalendarItem .fromJson ({
72
- ...row,
73
- });
39
+ CalendarItemMapper .fromMap (row);
74
40
75
41
CalendarItemType get type {
76
42
if (start == null && end == null ) {
@@ -88,6 +54,85 @@ class CalendarItem
88
54
}
89
55
90
56
Map <String , dynamic > toDatabase () => {
91
- ...toJson (),
57
+ ...toMap (),
92
58
};
93
59
}
60
+
61
+ @MappableClass ()
62
+ final class FixedCalendarItem extends CalendarItem
63
+ with FixedCalendarItemMappable {
64
+ const FixedCalendarItem ({
65
+ super .id,
66
+ super .name,
67
+ super .description,
68
+ super .location,
69
+ super .groupId,
70
+ super .placeId,
71
+ super .eventId,
72
+ super .start,
73
+ super .end,
74
+ super .status,
75
+ });
76
+ }
77
+
78
+ @MappableClass ()
79
+ final class RepeatingCalendarItem extends CalendarItem
80
+ with RepeatingCalendarItemMappable {
81
+ final RepeatType repeatType;
82
+ final int interval, variation, count;
83
+ final DateTime ? until;
84
+ final List <int > exceptions;
85
+
86
+ const RepeatingCalendarItem ({
87
+ super .id,
88
+ super .name,
89
+ super .description,
90
+ super .location,
91
+ super .groupId,
92
+ super .placeId,
93
+ super .eventId,
94
+ super .start,
95
+ super .end,
96
+ super .status,
97
+ this .repeatType = RepeatType .daily,
98
+ this .interval = 1 ,
99
+ this .variation = 0 ,
100
+ this .count = 0 ,
101
+ this .until,
102
+ this .exceptions = const [],
103
+ });
104
+ }
105
+
106
+ @MappableClass ()
107
+ final class AutoCalendarItem extends CalendarItem
108
+ with AutoCalendarItemMappable {
109
+ final RepeatType repeatType;
110
+ final int interval, variation, count;
111
+ final DateTime ? until;
112
+ final List <int > exceptions;
113
+ final Uint8List ? autoGroupId;
114
+ final DateTime ? searchStart;
115
+ final int autoDuration;
116
+
117
+ const AutoCalendarItem ({
118
+ super .id,
119
+ super .name,
120
+ super .description,
121
+ super .location,
122
+ super .groupId,
123
+ super .placeId,
124
+ super .eventId,
125
+ super .status,
126
+ super .start,
127
+ super .end,
128
+ this .repeatType = RepeatType .daily,
129
+ this .interval = 1 ,
130
+ this .variation = 0 ,
131
+ this .count = 0 ,
132
+ this .until,
133
+ this .exceptions = const [],
134
+ this .autoGroupId,
135
+ this .searchStart,
136
+ this .autoDuration = 60 ,
137
+ });
138
+ }
0 commit comments