@@ -25,7 +25,6 @@ class CalendarItemDatabaseService extends CalendarItemService
2525 description TEXT NOT NULL DEFAULT '',
2626 location VARCHAR(100) NOT NULL DEFAULT '',
2727 eventId BLOB(16),
28- groupId BLOB(16),
2928 start INTEGER,
3029 end INTEGER,
3130 status VARCHAR(20) NOT NULL DEFAULT 'confirmed',
@@ -44,18 +43,19 @@ class CalendarItemDatabaseService extends CalendarItemService
4443 }
4544
4645 @override
47- Future <List <ConnectedModel <CalendarItem , Event ?>>> getCalendarItems (
48- {List <EventStatus >? status,
49- Uint8List ? eventId,
50- List <Uint8List >? groupIds,
51- List <Uint8List >? resourceIds,
52- bool pending = false ,
53- int offset = 0 ,
54- int limit = 50 ,
55- DateTime ? start,
56- DateTime ? end,
57- DateTime ? date,
58- String search = '' }) async {
46+ Future <List <ConnectedModel <CalendarItem , Event ?>>> getCalendarItems ({
47+ List <EventStatus >? status,
48+ Uint8List ? eventId,
49+ List <Uint8List >? groupIds,
50+ List <Uint8List >? resourceIds,
51+ bool pending = false ,
52+ int offset = 0 ,
53+ int limit = 50 ,
54+ DateTime ? start,
55+ DateTime ? end,
56+ DateTime ? date,
57+ String search = '' ,
58+ }) async {
5959 String ? where;
6060 List <Object ?>? whereArgs;
6161 if (status != null ) {
@@ -72,8 +72,9 @@ class CalendarItemDatabaseService extends CalendarItemService
7272 }
7373 if (date != null ) {
7474 var startCalendarItem = date.onlyDate ();
75- var endCalendarItem =
76- startCalendarItem.add (Duration (hours: 23 , minutes: 59 , seconds: 59 ));
75+ var endCalendarItem = startCalendarItem.add (
76+ const Duration (hours: 23 , minutes: 59 , seconds: 59 ),
77+ );
7778 where = where == null
7879 ? '(start BETWEEN ? AND ? OR end BETWEEN ? AND ? OR (start <= ? AND end >= ?))'
7980 : '$where AND (start BETWEEN ? AND ? OR end BETWEEN ? AND ? OR (start <= ? AND end >= ?))' ;
@@ -101,8 +102,8 @@ class CalendarItemDatabaseService extends CalendarItemService
101102 if (groupIds != null ) {
102103 final placeholders = List .filled (groupIds.length, '?' ).join (', ' );
103104 final statement =
104- "(calendarItems.id IN (SELECT itemId FROM groupResources WHERE groupId IN ($placeholders )) OR "
105- "calendarItems.eventId IN (SELECT eventId FROM eventResources WHERE groupId IN ($placeholders )))" ;
105+ "(calendarItems.id IN (SELECT itemId FROM calendarItemGroups WHERE groupId IN ($placeholders )) OR "
106+ "calendarItems.eventId IN (SELECT eventId FROM eventGroups WHERE groupId IN ($placeholders )))" ;
106107 where = where == null ? statement : '$where AND $statement ' ;
107108 whereArgs = [...? whereArgs, ...groupIds, ...groupIds];
108109 }
@@ -118,13 +119,13 @@ class CalendarItemDatabaseService extends CalendarItemService
118119 where = where == null ? statement : '$where AND $statement ' ;
119120 whereArgs = [...? whereArgs, ...resourceIds, ...resourceIds];
120121 }
122+
121123 const eventPrefix = "event_" ;
122124 final result = await db? .query (
123125 "calendarItems LEFT JOIN events ON events.id = calendarItems.eventId" ,
124126 columns: [
125127 "events.id AS ${eventPrefix }id" ,
126128 "events.parentId AS ${eventPrefix }parentId" ,
127- "events.groupId AS ${eventPrefix }groupId" ,
128129 "events.blocked AS ${eventPrefix }blocked" ,
129130 "events.name AS ${eventPrefix }name" ,
130131 "events.description AS ${eventPrefix }description" ,
@@ -135,17 +136,27 @@ class CalendarItemDatabaseService extends CalendarItemService
135136 where: where,
136137 whereArgs: whereArgs,
137138 );
138- return result? .map ((e) {
139- return ConnectedModel <CalendarItem , Event ?>(
140- CalendarItem .fromDatabase (e),
141- e['${eventPrefix }id' ] == null
142- ? null
143- : Event .fromDatabase (Map .fromEntries (e.entries
144- .where ((element) => element.key.startsWith (eventPrefix))
145- .map ((e) => MapEntry (
146- e.key.substring (eventPrefix.length), e.value)))),
147- );
148- }).toList () ??
139+ return result
140+ ? .map (
141+ (e) => ConnectedModel <CalendarItem , Event ?>(
142+ CalendarItem .fromDatabase (e),
143+ e['${eventPrefix }id' ] == null
144+ ? null
145+ : Event .fromDatabase (
146+ Map .fromEntries (e.entries
147+ .where (
148+ (element) => element.key.startsWith (eventPrefix),
149+ )
150+ .map (
151+ (el) => MapEntry (
152+ el.key.substring (eventPrefix.length),
153+ el.value,
154+ ),
155+ )),
156+ ),
157+ ),
158+ )
159+ .toList () ??
149160 [];
150161 }
151162
0 commit comments