Skip to content

Commit 2b98abb

Browse files
authored
Merge pull request #82 from LinwoodDev/feature/resource-users-connections
Add resources and advanced user management
2 parents fc10230 + 1c3c98d commit 2b98abb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1940
-1572
lines changed

api/lib/models/cached.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:dart_mappable/dart_mappable.dart';
2+
import 'package:flow_api/services/database.dart';
23

34
import 'event/item/model.dart';
45
import 'event/model.dart';
@@ -27,19 +28,23 @@ class CachedData with CachedDataMappable {
2728
lastUpdated: other.lastUpdated ?? lastUpdated,
2829
events: [
2930
...events,
30-
...other.events.where((e) => !events.any((e2) => e2.id == e.id))
31+
...other.events
32+
.where((e) => !events.any((e2) => equalUint8List(e2.id, e.id)))
3133
],
3234
notebooks: [
3335
...notebooks,
34-
...other.notebooks.where((e) => !notebooks.any((e2) => e2.id == e.id))
36+
...other.notebooks
37+
.where((e) => !notebooks.any((e2) => equalUint8List(e2.id, e.id)))
3538
],
3639
items: [
3740
...items,
38-
...other.items.where((e) => !items.any((e2) => e2.id == e.id))
41+
...other.items
42+
.where((e) => !items.any((e2) => equalUint8List(e2.id, e.id)))
3943
],
4044
notes: [
4145
...notes,
42-
...other.notes.where((e) => !notes.any((e2) => e2.id == e.id))
46+
...other.notes
47+
.where((e) => !notes.any((e2) => equalUint8List(e2.id, e.id)))
4348
],
4449
);
4550
}

api/lib/models/event/database.dart

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,19 @@ class EventDatabaseService extends EventService with TableService {
1515
}
1616

1717
@override
18-
FutureOr<void> create(Database db) async {
18+
FutureOr<void> create(DatabaseExecutor db, [String name = 'events']) async {
1919
await db.execute("""
20-
CREATE TABLE IF NOT EXISTS events (
20+
CREATE TABLE IF NOT EXISTS $name (
2121
id BLOB(16) PRIMARY KEY,
2222
parentId BLOB(16),
2323
groupId BLOB(16),
24-
placeId BLOB(16),
2524
blocked INTEGER NOT NULL DEFAULT 1,
2625
name VARCHAR(100) NOT NULL DEFAULT '',
2726
description TEXT NOT NULL DEFAULT '',
2827
location TEXT NOT NULL DEFAULT '',
2928
extra TEXT,
3029
FOREIGN KEY (parentId) REFERENCES events(id) ON DELETE CASCADE,
31-
FOREIGN KEY (groupId) REFERENCES groups(id) ON DELETE CASCADE,
32-
FOREIGN KEY (placeId) REFERENCES places(id) ON DELETE CASCADE
30+
FOREIGN KEY (groupId) REFERENCES groups(id) ON DELETE CASCADE
3331
)
3432
""");
3533
}
@@ -61,7 +59,7 @@ class EventDatabaseService extends EventService with TableService {
6159
@override
6260
Future<List<Event>> getEvents(
6361
{Uint8List? groupId,
64-
Uint8List? placeId,
62+
List<Uint8List>? resourceIds,
6563
int offset = 0,
6664
int limit = 50,
6765
String search = ''}) async {
@@ -73,11 +71,13 @@ class EventDatabaseService extends EventService with TableService {
7371
}
7472
if (groupId != null) {
7573
where = where == null ? 'groupId = ?' : '$where AND groupId = ?';
76-
whereArgs = whereArgs == null ? [groupId] : [...whereArgs, groupId];
74+
whereArgs = [...?whereArgs, groupId];
7775
}
78-
if (placeId != null) {
79-
where = where == null ? 'placeId = ?' : '$where AND placeId = ?';
80-
whereArgs = whereArgs == null ? [placeId] : [...whereArgs, placeId];
76+
if (resourceIds != null) {
77+
final statement =
78+
"id IN (SELECT itemId FROM eventResources WHERE resourceId IN (${resourceIds.map((e) => '?').join(', ')}))";
79+
where = where == null ? statement : '$where AND $statement';
80+
whereArgs = [...?whereArgs, ...resourceIds];
8181
}
8282
final result = await db?.query(
8383
'events',
@@ -90,9 +90,6 @@ class EventDatabaseService extends EventService with TableService {
9090
return result.map(Event.fromDatabase).toList();
9191
}
9292

93-
@override
94-
FutureOr<void> migrate(Database db, int version) {}
95-
9693
@override
9794
FutureOr<bool> updateEvent(Event event) async {
9895
return await db?.update(

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class CalendarItemDatabaseService extends CalendarItemService
2525
location VARCHAR(100) NOT NULL DEFAULT '',
2626
eventId BLOB(16),
2727
groupId BLOB(16),
28-
placeId BLOB(16),
2928
start INTEGER,
3029
end INTEGER,
3130
status VARCHAR(20) NOT NULL DEFAULT 'confirmed',
@@ -58,7 +57,7 @@ class CalendarItemDatabaseService extends CalendarItemService
5857
{List<EventStatus>? status,
5958
Uint8List? eventId,
6059
Uint8List? groupId,
61-
Uint8List? placeId,
60+
List<Uint8List>? resourceIds,
6261
bool pending = false,
6362
int offset = 0,
6463
int limit = 50,
@@ -113,23 +112,23 @@ class CalendarItemDatabaseService extends CalendarItemService
113112
where = where == null ? statement : '$where AND $statement';
114113
whereArgs = [...?whereArgs, groupId, groupId];
115114
}
116-
if (placeId != null) {
117-
final statement = "(placeId = ? OR events.placeId = ?)";
118-
where = where == null ? statement : '$where AND $statement';
119-
whereArgs = [...?whereArgs, placeId, placeId];
120-
}
121115
if (eventId != null) {
122116
where = where == null ? 'eventId = ?' : '$where AND eventId = ?';
123117
whereArgs = [...?whereArgs, eventId];
124118
}
119+
if (resourceIds != null) {
120+
final statement =
121+
"(calendarItems.id IN (SELECT itemId FROM calendarItemResources WHERE resourceId IN (${List.filled(resourceIds.length, '?').join(', ')})) OR events.id IN (SELECT eventId FROM eventResources WHERE resourceId IN (${List.filled(resourceIds.length, '?').join(', ')})))";
122+
where = where == null ? statement : '$where AND $statement';
123+
whereArgs = [...?whereArgs, ...resourceIds, ...resourceIds];
124+
}
125125
const eventPrefix = "event_";
126126
final result = await db?.query(
127127
"calendarItems LEFT JOIN events ON events.id = calendarItems.eventId",
128128
columns: [
129129
"events.id AS ${eventPrefix}id",
130130
"events.parentId AS ${eventPrefix}parentId",
131131
"events.groupId AS ${eventPrefix}groupId",
132-
"events.placeId AS ${eventPrefix}placeId",
133132
"events.blocked AS ${eventPrefix}blocked",
134133
"events.name AS ${eventPrefix}name",
135134
"events.description AS ${eventPrefix}description",
@@ -215,7 +214,7 @@ abstract class CalendarItemDatabaseServiceLinker extends CalendarItemService
215214
List<EventStatus>? status,
216215
Uint8List? eventId,
217216
Uint8List? groupId,
218-
Uint8List? placeId,
217+
List<Uint8List>? resourceIds,
219218
bool pending = false,
220219
int offset = 0,
221220
int limit = 50,
@@ -228,7 +227,7 @@ abstract class CalendarItemDatabaseServiceLinker extends CalendarItemService
228227
status: status,
229228
eventId: eventId,
230229
groupId: groupId,
231-
placeId: placeId,
230+
resourceIds: resourceIds,
232231
pending: pending,
233232
offset: offset,
234233
limit: limit,

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ sealed class CalendarItem
1818
@override
1919
final String name, description;
2020
final String location;
21-
final Uint8List? groupId, placeId, eventId;
21+
final Uint8List? groupId, eventId;
2222
final DateTime? start, end;
2323
final EventStatus status;
2424

@@ -28,15 +28,14 @@ sealed class CalendarItem
2828
this.description = '',
2929
this.location = '',
3030
this.groupId,
31-
this.placeId,
3231
this.eventId,
3332
this.start,
3433
this.end,
3534
this.status = EventStatus.confirmed,
3635
});
3736

3837
factory CalendarItem.fromDatabase(Map<String, dynamic> row) =>
39-
CalendarItemMapper.fromMap(row);
38+
FixedCalendarItemMapper.fromMap(row);
4039

4140
CalendarItemType get type {
4241
if (start == null && end == null) {
@@ -67,7 +66,6 @@ final class FixedCalendarItem extends CalendarItem
6766
super.description,
6867
super.location,
6968
super.groupId,
70-
super.placeId,
7169
super.eventId,
7270
super.start,
7371
super.end,
@@ -89,7 +87,6 @@ final class RepeatingCalendarItem extends CalendarItem
8987
super.description,
9088
super.location,
9189
super.groupId,
92-
super.placeId,
9390
super.eventId,
9491
super.start,
9592
super.end,
@@ -120,7 +117,6 @@ final class AutoCalendarItem extends CalendarItem
120117
super.description,
121118
super.location,
122119
super.groupId,
123-
super.placeId,
124120
super.eventId,
125121
super.status,
126122
super.start,

0 commit comments

Comments
 (0)