6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 2403bf39
Changed files
comwell_key_app/lib/database/daos/bookings_dao.dart | 2 +- comwell_key_app/lib/database/tables/booking_table.dart | 7 ++++++- comwell_key_app/lib/database/tables/user_table.dart | 6 +++++- comwell_key_app/lib/overview/repository/overview_repository.dart | 4 ++-- 4 files changed, 14 insertions(+), 5 deletions(-)
Diff
diff --git a/comwell_key_app/lib/database/daos/bookings_dao.dart b/comwell_key_app/lib/database/daos/bookings_dao.dart
index a1a3cc48..89286958 100644
--- a/comwell_key_app/lib/database/daos/bookings_dao.dart
+++ b/comwell_key_app/lib/database/daos/bookings_dao.dart
@@ -25,7 +25,7 @@ class BookingsDao extends DatabaseAccessor<ComwellDatabase>
return BookingEntityCompanion.insert(
id: booking.id, json: json, status: status.toString());
});
- await batch((batch) => batch.insertAll(bookingEntity, entities));
+ await batch((batch) => batch.insertAll(bookingEntity, entities, mode: InsertMode.insertOrReplace));
}
Future<void> insertBookings(Bookings bookings) async {
diff --git a/comwell_key_app/lib/database/tables/booking_table.dart b/comwell_key_app/lib/database/tables/booking_table.dart
index bf612393..8fb22660 100644
--- a/comwell_key_app/lib/database/tables/booking_table.dart
+++ b/comwell_key_app/lib/database/tables/booking_table.dart
@@ -3,6 +3,11 @@ import 'package:drift/drift.dart';
@DataClassName('BookingDb')
class BookingEntity extends Table {
TextColumn get id => text().unique()();
+
TextColumn get status => text()();
+
TextColumn get json => text()();
-}
\ No newline at end of file
+
+ @override
+ Set<Column<Object>> get primaryKey => {id};
+}
diff --git a/comwell_key_app/lib/database/tables/user_table.dart b/comwell_key_app/lib/database/tables/user_table.dart
index b5d6c0a7..eafca514 100644
--- a/comwell_key_app/lib/database/tables/user_table.dart
+++ b/comwell_key_app/lib/database/tables/user_table.dart
@@ -3,5 +3,9 @@ import 'package:drift/drift.dart';
@DataClassName('UserDb')
class UserEntity extends Table {
TextColumn get id => text().unique()();
+
TextColumn get json => text()();
-}
\ No newline at end of file
+
+ @override
+ Set<Column<Object>> get primaryKey => {id};
+}
diff --git a/comwell_key_app/lib/overview/repository/overview_repository.dart b/comwell_key_app/lib/overview/repository/overview_repository.dart
index 16b5b869..38230e38 100644
--- a/comwell_key_app/lib/overview/repository/overview_repository.dart
+++ b/comwell_key_app/lib/overview/repository/overview_repository.dart
@@ -14,7 +14,7 @@ class OverviewRepository {
//final response = await api.fetchAllBookingsForUser(userId);
//if (response != null) {
final bookings = Bookings.fromJson(response);
- //await database.bookingsDao.insertBookings(bookings);
+ await database.bookingsDao.insertBookings(bookings);
return bookings;
// } else {
// throw Exception('Failed to fetch bookings');
@@ -22,7 +22,7 @@ class OverviewRepository {
}
Future<Booking?> findBooking(String bookingReference, String lastName) async {
- return await Booking.fromJson(json);
+ return Booking.fromJson(json);
}
}