Skip to content

Commit 4c3321c

Browse files
committed
Fix many fetching problems, closes #86
1 parent 20ee4f6 commit 4c3321c

File tree

15 files changed

+74
-76
lines changed

15 files changed

+74
-76
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
with:
2626
java-version: "17"
2727
distribution: "temurin"
28-
- uses: subosito/flutter-action@v2.18.0
28+
- uses: subosito/flutter-action@v2.19.0
2929
with:
3030
flutter-version-file: app/pubspec.yaml
3131
- name: 📦 Get dependencies
@@ -99,7 +99,7 @@ jobs:
9999
run: |
100100
choco install yq
101101
choco install innosetup
102-
- uses: subosito/flutter-action@v2.18.0
102+
- uses: subosito/flutter-action@v2.19.0
103103
with:
104104
flutter-version-file: app/pubspec.yaml
105105
- name: ✅ Enable platforms
@@ -183,7 +183,7 @@ jobs:
183183
libsecret-1-dev \
184184
libjsoncpp-dev \
185185
rpm
186-
- uses: subosito/flutter-action@v2.18.0
186+
- uses: subosito/flutter-action@v2.19.0
187187
with:
188188
flutter-version-file: app/pubspec.yaml
189189
channel: 'master'
@@ -312,7 +312,7 @@ jobs:
312312
alien \
313313
libsecret-1-dev \
314314
libjsoncpp-dev
315-
- uses: subosito/flutter-action@v2.18.0
315+
- uses: subosito/flutter-action@v2.19.0
316316
with:
317317
flutter-version-file: app/pubspec.yaml
318318
channel: 'master'
@@ -377,7 +377,7 @@ jobs:
377377
steps:
378378
- name: ⬆️ Checkout
379379
uses: actions/checkout@v4
380-
- uses: subosito/flutter-action@v2.18.0
380+
- uses: subosito/flutter-action@v2.19.0
381381
with:
382382
flutter-version-file: app/pubspec.yaml
383383
- uses: actions/setup-python@v5
@@ -429,7 +429,7 @@ jobs:
429429
steps:
430430
- name: ⬆️ Checkout
431431
uses: actions/checkout@v4
432-
- uses: subosito/flutter-action@v2.18.0
432+
- uses: subosito/flutter-action@v2.19.0
433433
with:
434434
flutter-version-file: app/pubspec.yaml
435435
- name: 📦 Get dependencies
@@ -719,7 +719,7 @@ jobs:
719719
with:
720720
java-version: "17"
721721
distribution: "temurin"
722-
- uses: subosito/flutter-action@v2.18.0
722+
- uses: subosito/flutter-action@v2.19.0
723723
with:
724724
flutter-version-file: app/pubspec.yaml
725725
- name: 📦 Get dependencies

.github/workflows/dart.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
steps:
1515
- name: ⬆️ Checkout
1616
uses: actions/checkout@v4
17-
- uses: subosito/flutter-action@v2.18.0
17+
- uses: subosito/flutter-action@v2.19.0
1818
with:
1919
flutter-version-file: app/pubspec.yaml
2020
- uses: actions/checkout@v4

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
steps:
5151
- name: ⬆️ Checkout
5252
uses: actions/checkout@v4
53-
- uses: subosito/flutter-action@v2.18.0
53+
- uses: subosito/flutter-action@v2.19.0
5454
with:
5555
flutter-version-file: app/pubspec.yaml
5656
- name: Install dependencies

.github/workflows/release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
with:
2222
token: ${{ secrets.CI_PAT }}
2323
fetch-depth: 0
24-
- uses: subosito/flutter-action@v2.18.0
24+
- uses: subosito/flutter-action@v2.19.0
2525
with:
2626
flutter-version-file: app/pubspec.yaml
2727
- name: Setup git
@@ -65,7 +65,7 @@ jobs:
6565
token: ${{ secrets.CI_PAT }}
6666
ref: ${{ github.ref }}
6767
fetch-depth: 0
68-
- uses: subosito/flutter-action@v2.18.0
68+
- uses: subosito/flutter-action@v2.19.0
6969
with:
7070
flutter-version-file: app/pubspec.yaml
7171
- name: Setup git
@@ -127,7 +127,7 @@ jobs:
127127
with:
128128
token: ${{ secrets.CI_PAT }}
129129
fetch-depth: 0
130-
- uses: subosito/flutter-action@v2.18.0
130+
- uses: subosito/flutter-action@v2.19.0
131131
with:
132132
flutter-version-file: app/pubspec.yaml
133133
- name: Setup git
@@ -190,7 +190,7 @@ jobs:
190190
echo "FLOW_BUILD_NUMBER=${FLOW_BUILD_NUMBER}" >> $GITHUB_ENV
191191
git config --global user.email "[email protected]"
192192
git config --global user.name "Linwood CI"
193-
- uses: subosito/flutter-action@v2.18.0
193+
- uses: subosito/flutter-action@v2.19.0
194194
with:
195195
flutter-version-file: app/pubspec.yaml
196196
- name: Bump version

api/lib/models/event/database.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ class EventDatabaseService extends EventService with TableService {
6868
whereArgs = ['%$search%'];
6969
}
7070
if (groupId != null) {
71-
where = where == null ? 'groupId = ?' : '$where AND groupId = ?';
71+
final statement =
72+
"id IN (SELECT eventId FROM eventGroups WHERE groupId = ?)";
73+
where = where == null ? statement : '$where AND $statement';
7274
whereArgs = [...?whereArgs, groupId];
7375
}
7476
if (resourceIds != null) {

api/lib/models/event/group.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class EventGroupDatabaseConnector extends DatabaseModelConnector<Group, Event> {
2323
'$tableName JOIN events ON eventId = events.id',
2424
limit: limit,
2525
offset: offset,
26-
where: '$connectedIdName = ?',
26+
where: 'groupId = ?',
2727
whereArgs: [itemId],
2828
);
2929
return result?.map((e) => Event.fromDatabase(e)).toList() ?? [];
@@ -36,7 +36,7 @@ class EventGroupDatabaseConnector extends DatabaseModelConnector<Group, Event> {
3636
'$tableName JOIN groups ON groupId = groups.id',
3737
limit: limit,
3838
offset: offset,
39-
where: '$itemIdName = ?',
39+
where: 'eventId = ?',
4040
whereArgs: [connectId],
4141
);
4242
return result?.map((e) => Group.fromDatabase(e)).toList() ?? [];

api/lib/models/event/item/database.dart

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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

api/lib/models/event/item/group.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CalendarItemGroupDatabaseConnector
2424
'$tableName JOIN calendarItems ON itemId = calendarItems.id',
2525
limit: limit,
2626
offset: offset,
27-
where: '$connectedIdName = ?',
27+
where: 'groupId = ?',
2828
whereArgs: [itemId],
2929
);
3030
return result?.map((e) => CalendarItem.fromDatabase(e)).toList() ?? [];
@@ -37,7 +37,7 @@ class CalendarItemGroupDatabaseConnector
3737
'$tableName JOIN groups ON groupId = groups.id',
3838
limit: limit,
3939
offset: offset,
40-
where: '$itemIdName = ?',
40+
where: 'itemId = ?',
4141
whereArgs: [connectId],
4242
);
4343
return result?.map((e) => Group.fromDatabase(e)).toList() ?? [];

api/lib/models/event/item/user.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CalendarItemUserDatabaseConnector
2424
'$tableName JOIN calendaritems ON itemId = calendarItems.id',
2525
limit: limit,
2626
offset: offset,
27-
where: '$connectedIdName = ?',
27+
where: 'userId = ?',
2828
whereArgs: [itemId],
2929
);
3030
return result?.map((e) => CalendarItem.fromDatabase(e)).toList() ?? [];
@@ -37,7 +37,7 @@ class CalendarItemUserDatabaseConnector
3737
'$tableName JOIN users ON userId = users.id',
3838
limit: limit,
3939
offset: offset,
40-
where: '$itemIdName = ?',
40+
where: 'itemId = ?',
4141
whereArgs: [connectId],
4242
);
4343
return result?.map((e) => User.fromDatabase(e)).toList() ?? [];

api/lib/models/event/user.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class EventUserDatabaseConnector extends DatabaseModelConnector<User, Event> {
2323
'$tableName JOIN events ON eventId = events.id',
2424
limit: limit,
2525
offset: offset,
26-
where: '$connectedIdName = ?',
26+
where: 'groupId = ?',
2727
whereArgs: [itemId],
2828
);
2929
return result?.map((e) => Event.fromDatabase(e)).toList() ?? [];
@@ -36,7 +36,7 @@ class EventUserDatabaseConnector extends DatabaseModelConnector<User, Event> {
3636
'$tableName JOIN users ON userId = users.id',
3737
limit: limit,
3838
offset: offset,
39-
where: '$itemIdName = ?',
39+
where: 'userId = ?',
4040
whereArgs: [connectId],
4141
);
4242
return result?.map((e) => User.fromDatabase(e)).toList() ?? [];

0 commit comments

Comments
 (0)