Skip to content

Commit f7ae613

Browse files
committed
Rename from place to resource
1 parent fc10230 commit f7ae613

31 files changed

+746
-710
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,17 @@ class CalendarItemDatabaseService extends CalendarItemService
5151
await txn.execute("ALTER TABLE calendarItems ADD placeId BLOB(16)");
5252
});
5353
}
54+
if (version < 4) {
55+
await db.transaction((txn) async {});
56+
}
5457
}
5558

5659
@override
5760
Future<List<ConnectedModel<CalendarItem, Event?>>> getCalendarItems(
5861
{List<EventStatus>? status,
5962
Uint8List? eventId,
6063
Uint8List? groupId,
61-
Uint8List? placeId,
64+
Uint8List? resourceId,
6265
bool pending = false,
6366
int offset = 0,
6467
int limit = 50,
@@ -113,10 +116,10 @@ class CalendarItemDatabaseService extends CalendarItemService
113116
where = where == null ? statement : '$where AND $statement';
114117
whereArgs = [...?whereArgs, groupId, groupId];
115118
}
116-
if (placeId != null) {
119+
if (resourceId != null) {
117120
final statement = "(placeId = ? OR events.placeId = ?)";
118121
where = where == null ? statement : '$where AND $statement';
119-
whereArgs = [...?whereArgs, placeId, placeId];
122+
whereArgs = [...?whereArgs, resourceId, resourceId];
120123
}
121124
if (eventId != null) {
122125
where = where == null ? 'eventId = ?' : '$where AND eventId = ?';
@@ -215,7 +218,7 @@ abstract class CalendarItemDatabaseServiceLinker extends CalendarItemService
215218
List<EventStatus>? status,
216219
Uint8List? eventId,
217220
Uint8List? groupId,
218-
Uint8List? placeId,
221+
Uint8List? resourceId,
219222
bool pending = false,
220223
int offset = 0,
221224
int limit = 50,
@@ -228,7 +231,7 @@ abstract class CalendarItemDatabaseServiceLinker extends CalendarItemService
228231
status: status,
229232
eventId: eventId,
230233
groupId: groupId,
231-
placeId: placeId,
234+
resourceId: resourceId,
232235
pending: pending,
233236
offset: offset,
234237
limit: limit,

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract class CalendarItemService extends ModelService {
1212
List<EventStatus>? status,
1313
Uint8List? eventId,
1414
Uint8List? groupId,
15-
Uint8List? placeId,
15+
Uint8List? resourceId,
1616
bool pending = false,
1717
int offset = 0,
1818
int limit = 50,
@@ -28,3 +28,9 @@ abstract class CalendarItemService extends ModelService {
2828

2929
FutureOr<bool> deleteCalendarItem(Uint8List id);
3030
}
31+
32+
abstract class CalendarItemResourceConnector<T> extends ModelService {
33+
FutureOr<void> connect(Uint8List calendarItemId, Uint8List resourceId);
34+
FutureOr<void> disconnect(Uint8List calendarItemId, Uint8List resourceId);
35+
FutureOr<bool> isConnected(Uint8List calendarItemId, Uint8List resourceId);
36+
}

api/lib/models/place/model.mapper.dart

Lines changed: 0 additions & 129 deletions
This file was deleted.

api/lib/models/place/service.dart

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import 'package:sqflite_common/sqlite_api.dart';
88
import 'model.dart';
99
import 'service.dart';
1010

11-
class PlaceDatabaseService extends PlaceService with TableService {
11+
class ResourceDatabaseService extends ResourceService with TableService {
1212
@override
1313
Future<void> create(Database db) {
1414
return db.execute("""
15-
CREATE TABLE IF NOT EXISTS places (
15+
CREATE TABLE IF NOT EXISTS resources (
1616
id BLOB(16) PRIMARY KEY,
1717
name VARCHAR(100) NOT NULL DEFAULT '',
1818
description TEXT,
@@ -22,66 +22,70 @@ class PlaceDatabaseService extends PlaceService with TableService {
2222
}
2323

2424
@override
25-
FutureOr<void> migrate(Database db, int version) {}
25+
FutureOr<void> migrate(Database db, int version) async {
26+
if (version < 5) {
27+
await db.execute("ALTER TABLE places RENAME TO resources");
28+
}
29+
}
2630

2731
@override
28-
Future<Place?> createPlace(Place place) async {
29-
final id = place.id ?? createUniqueUint8List();
30-
place = place.copyWith(id: id);
31-
final row = await db?.insert('places', place.toDatabase());
32+
Future<Resource?> createResource(Resource resource) async {
33+
final id = resource.id ?? createUniqueUint8List();
34+
resource = resource.copyWith(id: id);
35+
final row = await db?.insert('resources', resource.toDatabase());
3236
if (row == null) return null;
33-
return place;
37+
return resource;
3438
}
3539

3640
@override
37-
Future<bool> deletePlace(Uint8List id) async {
41+
Future<bool> deleteResource(Uint8List id) async {
3842
return await db?.delete(
39-
'places',
43+
'resources',
4044
where: 'id = ?',
4145
whereArgs: [id],
4246
) ==
4347
1;
4448
}
4549

4650
@override
47-
Future<List<Place>> getPlaces(
51+
Future<List<Resource>> getResources(
4852
{int offset = 0, int limit = 50, String search = ''}) async {
4953
final where = search.isEmpty ? null : 'name LIKE ?';
5054
final whereArgs = search.isEmpty ? null : ['%$search%'];
5155
final result = await db?.query(
52-
'places',
56+
'resources',
5357
limit: limit,
5458
offset: offset,
5559
where: where,
5660
whereArgs: whereArgs,
5761
);
5862
if (result == null) return [];
59-
return result.map(Place.fromDatabase).toList();
63+
return result.map(Resource.fromDatabase).toList();
6064
}
6165

6266
@override
63-
FutureOr<Place?> getPlace(Uint8List id) async {
67+
FutureOr<Resource?> getResource(Uint8List id) async {
6468
final result = await db?.query(
65-
'places',
69+
'resources',
6670
where: 'id = ?',
6771
whereArgs: [id],
6872
);
69-
return result?.map(Place.fromDatabase).firstOrNull;
73+
return result?.map(Resource.fromDatabase).firstOrNull;
7074
}
7175

7276
@override
73-
Future<bool> updatePlace(Place place) async {
77+
Future<bool> updateResource(Resource resource) async {
7478
return await db?.update(
75-
'places',
76-
place.toDatabase()..remove('id'),
79+
'resources',
80+
resource.toDatabase()..remove('id'),
7781
where: 'id = ?',
78-
whereArgs: [place.id],
82+
whereArgs: [resource.id],
7983
) ==
8084
1;
8185
}
8286

8387
@override
8488
Future<void> clear() async {
85-
await db?.delete('places');
89+
await db?.delete('resources');
8690
}
8791
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,23 @@ import '../model.dart';
66
part 'model.mapper.dart';
77

88
@MappableClass()
9-
class Place with PlaceMappable, IdentifiedModel, NamedModel, DescriptiveModel {
9+
class Resource
10+
with ResourceMappable, IdentifiedModel, NamedModel, DescriptiveModel {
1011
@override
1112
final Uint8List? id;
1213
@override
1314
final String name, description;
1415
final String address;
1516

16-
const Place({
17+
const Resource({
1718
this.id,
1819
this.name = '',
1920
this.description = '',
2021
this.address = '',
2122
});
2223

23-
factory Place.fromDatabase(Map<String, dynamic> row) => PlaceMapper.fromMap({
24+
factory Resource.fromDatabase(Map<String, dynamic> row) =>
25+
ResourceMapper.fromMap({
2426
...row,
2527
});
2628

0 commit comments

Comments
 (0)