6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 518a41c3

AuthorMikkel Thygesen<mth@dwarf.dk>
Date2025-01-15 13:27:17 +0100
464: Implemented drift database for user and bookings

Changed files

.../lib/.generated/database/comwell_db.g.dart      | 709 +++++++++++++++++++++
 .../.generated/database/daos/bookings_dao.g.dart   |   8 +
 .../lib/.generated/database/daos/user_dao.g.dart   |   8 +
 .../lib/.generated/overview/models/booking.g.dart  |  50 ++
 .../lib/.generated/overview/models/bookings.g.dart |  25 +
 .../overview/models/payment_details.g.dart         |  33 +
 .../.generated/profile_settings/model/user.g.dart  |  31 +
 .../services/adyen/adyen_line_item.g.dart          |  20 +-
 comwell_key_app/lib/common/const.dart              |   2 +-
 comwell_key_app/lib/database/comwell_db.dart       |  81 +++
 .../lib/database/daos/bookings_dao.dart            |  69 ++
 comwell_key_app/lib/database/daos/user_dao.dart    |  30 +
 .../lib/database/tables/booking_table.dart         |   8 +
 .../lib/database/tables/user_table.dart            |   7 +
 comwell_key_app/lib/overview/models/booking.dart   |  58 +-
 comwell_key_app/lib/overview/models/bookings.dart  |  17 +-
 .../lib/overview/models/payment_details.dart       |  26 +-
 .../overview/repository/overview_repository.dart   |   7 +-
 .../pregistration/pregistration_repository.dart    |   2 +-
 .../lib/profile_settings/model/user.dart           |  35 +-
 .../repostiory/profile_settings_repository.dart    |  10 +-
 comwell_key_app/lib/utils/locator.dart             |   2 +
 .../linux/flutter/generated_plugin_registrant.cc   |   4 +
 .../linux/flutter/generated_plugins.cmake          |   1 +
 .../macos/Flutter/GeneratedPluginRegistrant.swift  |   2 +
 comwell_key_app/pubspec.yaml                       |   7 +
 .../windows/flutter/generated_plugin_registrant.cc |   3 +
 .../windows/flutter/generated_plugins.cmake        |   1 +
 28 files changed, 1138 insertions(+), 118 deletions(-)

Diff

diff --git a/comwell_key_app/lib/.generated/database/comwell_db.g.dart b/comwell_key_app/lib/.generated/database/comwell_db.g.dart
new file mode 100644
index 00000000..99db1942
--- /dev/null
+++ b/comwell_key_app/lib/.generated/database/comwell_db.g.dart
@@ -0,0 +1,709 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of '../../database/comwell_db.dart';
+
+// ignore_for_file: type=lint
+class $BookingEntityTable extends BookingEntity
+ with TableInfo<$BookingEntityTable, BookingDb> {
+ @override
+ final GeneratedDatabase attachedDatabase;
+ final String? _alias;
+ $BookingEntityTable(this.attachedDatabase, [this._alias]);
+ static const VerificationMeta _idMeta = const VerificationMeta('id');
+ @override
+ late final GeneratedColumn<String> id = GeneratedColumn<String>(
+ 'id', aliasedName, false,
+ type: DriftSqlType.string,
+ requiredDuringInsert: true,
+ defaultConstraints: GeneratedColumn.constraintIsAlways('UNIQUE'));
+ static const VerificationMeta _statusMeta = const VerificationMeta('status');
+ @override
+ late final GeneratedColumn<String> status = GeneratedColumn<String>(
+ 'status', aliasedName, false,
+ type: DriftSqlType.string, requiredDuringInsert: true);
+ static const VerificationMeta _jsonMeta = const VerificationMeta('json');
+ @override
+ late final GeneratedColumn<String> json = GeneratedColumn<String>(
+ 'json', aliasedName, false,
+ type: DriftSqlType.string, requiredDuringInsert: true);
+ @override
+ List<GeneratedColumn> get $columns => [id, status, json];
+ @override
+ String get aliasedName => _alias ?? actualTableName;
+ @override
+ String get actualTableName => $name;
+ static const String $name = 'booking_entity';
+ @override
+ VerificationContext validateIntegrity(Insertable<BookingDb> instance,
+ {bool isInserting = false}) {
+ final context = VerificationContext();
+ final data = instance.toColumns(true);
+ if (data.containsKey('id')) {
+ context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta));
+ } else if (isInserting) {
+ context.missing(_idMeta);
+ }
+ if (data.containsKey('status')) {
+ context.handle(_statusMeta,
+ status.isAcceptableOrUnknown(data['status']!, _statusMeta));
+ } else if (isInserting) {
+ context.missing(_statusMeta);
+ }
+ if (data.containsKey('json')) {
+ context.handle(
+ _jsonMeta, json.isAcceptableOrUnknown(data['json']!, _jsonMeta));
+ } else if (isInserting) {
+ context.missing(_jsonMeta);
+ }
+ return context;
+ }
+
+ @override
+ Set<GeneratedColumn> get $primaryKey => const {};
+ @override
+ BookingDb map(Map<String, dynamic> data, {String? tablePrefix}) {
+ final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
+ return BookingDb(
+ id: attachedDatabase.typeMapping
+ .read(DriftSqlType.string, data['${effectivePrefix}id'])!,
+ status: attachedDatabase.typeMapping
+ .read(DriftSqlType.string, data['${effectivePrefix}status'])!,
+ json: attachedDatabase.typeMapping
+ .read(DriftSqlType.string, data['${effectivePrefix}json'])!,
+ );
+ }
+
+ @override
+ $BookingEntityTable createAlias(String alias) {
+ return $BookingEntityTable(attachedDatabase, alias);
+ }
+}
+
+class BookingDb extends DataClass implements Insertable<BookingDb> {
+ final String id;
+ final String status;
+ final String json;
+ const BookingDb({required this.id, required this.status, required this.json});
+ @override
+ Map<String, Expression> toColumns(bool nullToAbsent) {
+ final map = <String, Expression>{};
+ map['id'] = Variable<String>(id);
+ map['status'] = Variable<String>(status);
+ map['json'] = Variable<String>(json);
+ return map;
+ }
+
+ BookingEntityCompanion toCompanion(bool nullToAbsent) {
+ return BookingEntityCompanion(
+ id: Value(id),
+ status: Value(status),
+ json: Value(json),
+ );
+ }
+
+ factory BookingDb.fromJson(Map<String, dynamic> json,
+ {ValueSerializer? serializer}) {
+ serializer ??= driftRuntimeOptions.defaultSerializer;
+ return BookingDb(
+ id: serializer.fromJson<String>(json['id']),
+ status: serializer.fromJson<String>(json['status']),
+ json: serializer.fromJson<String>(json['json']),
+ );
+ }
+ @override
+ Map<String, dynamic> toJson({ValueSerializer? serializer}) {
+ serializer ??= driftRuntimeOptions.defaultSerializer;
+ return <String, dynamic>{
+ 'id': serializer.toJson<String>(id),
+ 'status': serializer.toJson<String>(status),
+ 'json': serializer.toJson<String>(json),
+ };
+ }
+
+ BookingDb copyWith({String? id, String? status, String? json}) => BookingDb(
+ id: id ?? this.id,
+ status: status ?? this.status,
+ json: json ?? this.json,
+ );
+ BookingDb copyWithCompanion(BookingEntityCompanion data) {
+ return BookingDb(
+ id: data.id.present ? data.id.value : this.id,
+ status: data.status.present ? data.status.value : this.status,
+ json: data.json.present ? data.json.value : this.json,
+ );
+ }
+
+ @override
+ String toString() {
+ return (StringBuffer('BookingDb(')
+ ..write('id: $id, ')
+ ..write('status: $status, ')
+ ..write('json: $json')
+ ..write(')'))
+ .toString();
+ }
+
+ @override
+ int get hashCode => Object.hash(id, status, json);
+ @override
+ bool operator ==(Object other) =>
+ identical(this, other) ||
+ (other is BookingDb &&
+ other.id == this.id &&
+ other.status == this.status &&
+ other.json == this.json);
+}
+
+class BookingEntityCompanion extends UpdateCompanion<BookingDb> {
+ final Value<String> id;
+ final Value<String> status;
+ final Value<String> json;
+ final Value<int> rowid;
+ const BookingEntityCompanion({
+ this.id = const Value.absent(),
+ this.status = const Value.absent(),
+ this.json = const Value.absent(),
+ this.rowid = const Value.absent(),
+ });
+ BookingEntityCompanion.insert({
+ required String id,
+ required String status,
+ required String json,
+ this.rowid = const Value.absent(),
+ }) : id = Value(id),
+ status = Value(status),
+ json = Value(json);
+ static Insertable<BookingDb> custom({
+ Expression<String>? id,
+ Expression<String>? status,
+ Expression<String>? json,
+ Expression<int>? rowid,
+ }) {
+ return RawValuesInsertable({
+ if (id != null) 'id': id,
+ if (status != null) 'status': status,
+ if (json != null) 'json': json,
+ if (rowid != null) 'rowid': rowid,
+ });
+ }
+
+ BookingEntityCompanion copyWith(
+ {Value<String>? id,
+ Value<String>? status,
+ Value<String>? json,
+ Value<int>? rowid}) {
+ return BookingEntityCompanion(
+ id: id ?? this.id,
+ status: status ?? this.status,
+ json: json ?? this.json,
+ rowid: rowid ?? this.rowid,
+ );
+ }
+
+ @override
+ Map<String, Expression> toColumns(bool nullToAbsent) {
+ final map = <String, Expression>{};
+ if (id.present) {
+ map['id'] = Variable<String>(id.value);
+ }
+ if (status.present) {
+ map['status'] = Variable<String>(status.value);
+ }
+ if (json.present) {
+ map['json'] = Variable<String>(json.value);
+ }
+ if (rowid.present) {
+ map['rowid'] = Variable<int>(rowid.value);
+ }
+ return map;
+ }
+
+ @override
+ String toString() {
+ return (StringBuffer('BookingEntityCompanion(')
+ ..write('id: $id, ')
+ ..write('status: $status, ')
+ ..write('json: $json, ')
+ ..write('rowid: $rowid')
+ ..write(')'))
+ .toString();
+ }
+}
+
+class $UserEntityTable extends UserEntity
+ with TableInfo<$UserEntityTable, UserDb> {
+ @override
+ final GeneratedDatabase attachedDatabase;
+ final String? _alias;
+ $UserEntityTable(this.attachedDatabase, [this._alias]);
+ static const VerificationMeta _idMeta = const VerificationMeta('id');
+ @override
+ late final GeneratedColumn<String> id = GeneratedColumn<String>(
+ 'id', aliasedName, false,
+ type: DriftSqlType.string,
+ requiredDuringInsert: true,
+ defaultConstraints: GeneratedColumn.constraintIsAlways('UNIQUE'));
+ static const VerificationMeta _jsonMeta = const VerificationMeta('json');
+ @override
+ late final GeneratedColumn<String> json = GeneratedColumn<String>(
+ 'json', aliasedName, false,
+ type: DriftSqlType.string, requiredDuringInsert: true);
+ @override
+ List<GeneratedColumn> get $columns => [id, json];
+ @override
+ String get aliasedName => _alias ?? actualTableName;
+ @override
+ String get actualTableName => $name;
+ static const String $name = 'user_entity';
+ @override
+ VerificationContext validateIntegrity(Insertable<UserDb> instance,
+ {bool isInserting = false}) {
+ final context = VerificationContext();
+ final data = instance.toColumns(true);
+ if (data.containsKey('id')) {
+ context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta));
+ } else if (isInserting) {
+ context.missing(_idMeta);
+ }
+ if (data.containsKey('json')) {
+ context.handle(
+ _jsonMeta, json.isAcceptableOrUnknown(data['json']!, _jsonMeta));
+ } else if (isInserting) {
+ context.missing(_jsonMeta);
+ }
+ return context;
+ }
+
+ @override
+ Set<GeneratedColumn> get $primaryKey => const {};
+ @override
+ UserDb map(Map<String, dynamic> data, {String? tablePrefix}) {
+ final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
+ return UserDb(
+ id: attachedDatabase.typeMapping
+ .read(DriftSqlType.string, data['${effectivePrefix}id'])!,
+ json: attachedDatabase.typeMapping
+ .read(DriftSqlType.string, data['${effectivePrefix}json'])!,
+ );
+ }
+
+ @override
+ $UserEntityTable createAlias(String alias) {
+ return $UserEntityTable(attachedDatabase, alias);
+ }
+}
+
+class UserDb extends DataClass implements Insertable<UserDb> {
+ final String id;
+ final String json;
+ const UserDb({required this.id, required this.json});
+ @override
+ Map<String, Expression> toColumns(bool nullToAbsent) {
+ final map = <String, Expression>{};
+ map['id'] = Variable<String>(id);
+ map['json'] = Variable<String>(json);
+ return map;
+ }
+
+ UserEntityCompanion toCompanion(bool nullToAbsent) {
+ return UserEntityCompanion(
+ id: Value(id),
+ json: Value(json),
+ );
+ }
+
+ factory UserDb.fromJson(Map<String, dynamic> json,
+ {ValueSerializer? serializer}) {
+ serializer ??= driftRuntimeOptions.defaultSerializer;
+ return UserDb(
+ id: serializer.fromJson<String>(json['id']),
+ json: serializer.fromJson<String>(json['json']),
+ );
+ }
+ @override
+ Map<String, dynamic> toJson({ValueSerializer? serializer}) {
+ serializer ??= driftRuntimeOptions.defaultSerializer;
+ return <String, dynamic>{
+ 'id': serializer.toJson<String>(id),
+ 'json': serializer.toJson<String>(json),
+ };
+ }
+
+ UserDb copyWith({String? id, String? json}) => UserDb(
+ id: id ?? this.id,
+ json: json ?? this.json,
+ );
+ UserDb copyWithCompanion(UserEntityCompanion data) {
+ return UserDb(
+ id: data.id.present ? data.id.value : this.id,
+ json: data.json.present ? data.json.value : this.json,
+ );
+ }
+
+ @override
+ String toString() {
+ return (StringBuffer('UserDb(')
+ ..write('id: $id, ')
+ ..write('json: $json')
+ ..write(')'))
+ .toString();
+ }
+
+ @override
+ int get hashCode => Object.hash(id, json);
+ @override
+ bool operator ==(Object other) =>
+ identical(this, other) ||
+ (other is UserDb && other.id == this.id && other.json == this.json);
+}
+
+class UserEntityCompanion extends UpdateCompanion<UserDb> {
+ final Value<String> id;
+ final Value<String> json;
+ final Value<int> rowid;
+ const UserEntityCompanion({
+ this.id = const Value.absent(),
+ this.json = const Value.absent(),
+ this.rowid = const Value.absent(),
+ });
+ UserEntityCompanion.insert({
+ required String id,
+ required String json,
+ this.rowid = const Value.absent(),
+ }) : id = Value(id),
+ json = Value(json);
+ static Insertable<UserDb> custom({
+ Expression<String>? id,
+ Expression<String>? json,
+ Expression<int>? rowid,
+ }) {
+ return RawValuesInsertable({
+ if (id != null) 'id': id,
+ if (json != null) 'json': json,
+ if (rowid != null) 'rowid': rowid,
+ });
+ }
+
+ UserEntityCompanion copyWith(
+ {Value<String>? id, Value<String>? json, Value<int>? rowid}) {
+ return UserEntityCompanion(
+ id: id ?? this.id,
+ json: json ?? this.json,
+ rowid: rowid ?? this.rowid,
+ );
+ }
+
+ @override
+ Map<String, Expression> toColumns(bool nullToAbsent) {
+ final map = <String, Expression>{};
+ if (id.present) {
+ map['id'] = Variable<String>(id.value);
+ }
+ if (json.present) {
+ map['json'] = Variable<String>(json.value);
+ }
+ if (rowid.present) {
+ map['rowid'] = Variable<int>(rowid.value);
+ }
+ return map;
+ }
+
+ @override
+ String toString() {
+ return (StringBuffer('UserEntityCompanion(')
+ ..write('id: $id, ')
+ ..write('json: $json, ')
+ ..write('rowid: $rowid')
+ ..write(')'))
+ .toString();
+ }
+}
+
+abstract class _$ComwellDatabase extends GeneratedDatabase {
+ _$ComwellDatabase(QueryExecutor e) : super(e);
+ $ComwellDatabaseManager get managers => $ComwellDatabaseManager(this);
+ late final $BookingEntityTable bookingEntity = $BookingEntityTable(this);
+ late final $UserEntityTable userEntity = $UserEntityTable(this);
+ late final BookingsDao bookingsDao = BookingsDao(this as ComwellDatabase);
+ late final UserDAO userDAO = UserDAO(this as ComwellDatabase);
+ @override
+ Iterable<TableInfo<Table, Object?>> get allTables =>
+ allSchemaEntities.whereType<TableInfo<Table, Object?>>();
+ @override
+ List<DatabaseSchemaEntity> get allSchemaEntities =>
+ [bookingEntity, userEntity];
+}
+
+typedef $$BookingEntityTableCreateCompanionBuilder = BookingEntityCompanion
+ Function({
+ required String id,
+ required String status,
+ required String json,
+ Value<int> rowid,
+});
+typedef $$BookingEntityTableUpdateCompanionBuilder = BookingEntityCompanion
+ Function({
+ Value<String> id,
+ Value<String> status,
+ Value<String> json,
+ Value<int> rowid,
+});
+
+class $$BookingEntityTableFilterComposer
+ extends Composer<_$ComwellDatabase, $BookingEntityTable> {
+ $$BookingEntityTableFilterComposer({
+ required super.$db,
+ required super.$table,
+ super.joinBuilder,
+ super.$addJoinBuilderToRootComposer,
+ super.$removeJoinBuilderFromRootComposer,
+ });
+ ColumnFilters<String> get id => $composableBuilder(
+ column: $table.id, builder: (column) => ColumnFilters(column));
+
+ ColumnFilters<String> get status => $composableBuilder(
+ column: $table.status, builder: (column) => ColumnFilters(column));
+
+ ColumnFilters<String> get json => $composableBuilder(
+ column: $table.json, builder: (column) => ColumnFilters(column));
+}
+
+class $$BookingEntityTableOrderingComposer
+ extends Composer<_$ComwellDatabase, $BookingEntityTable> {
+ $$BookingEntityTableOrderingComposer({
+ required super.$db,
+ required super.$table,
+ super.joinBuilder,
+ super.$addJoinBuilderToRootComposer,
+ super.$removeJoinBuilderFromRootComposer,
+ });
+ ColumnOrderings<String> get id => $composableBuilder(
+ column: $table.id, builder: (column) => ColumnOrderings(column));
+
+ ColumnOrderings<String> get status => $composableBuilder(
+ column: $table.status, builder: (column) => ColumnOrderings(column));
+
+ ColumnOrderings<String> get json => $composableBuilder(
+ column: $table.json, builder: (column) => ColumnOrderings(column));
+}
+
+class $$BookingEntityTableAnnotationComposer
+ extends Composer<_$ComwellDatabase, $BookingEntityTable> {
+ $$BookingEntityTableAnnotationComposer({
+ required super.$db,
+ required super.$table,
+ super.joinBuilder,
+ super.$addJoinBuilderToRootComposer,
+ super.$removeJoinBuilderFromRootComposer,
+ });
+ GeneratedColumn<String> get id =>
+ $composableBuilder(column: $table.id, builder: (column) => column);
+
+ GeneratedColumn<String> get status =>
+ $composableBuilder(column: $table.status, builder: (column) => column);
+
+ GeneratedColumn<String> get json =>
+ $composableBuilder(column: $table.json, builder: (column) => column);
+}
+
+class $$BookingEntityTableTableManager extends RootTableManager<
+ _$ComwellDatabase,
+ $BookingEntityTable,
+ BookingDb,
+ $$BookingEntityTableFilterComposer,
+ $$BookingEntityTableOrderingComposer,
+ $$BookingEntityTableAnnotationComposer,
+ $$BookingEntityTableCreateCompanionBuilder,
+ $$BookingEntityTableUpdateCompanionBuilder,
+ (
+ BookingDb,
+ BaseReferences<_$ComwellDatabase, $BookingEntityTable, BookingDb>
+ ),
+ BookingDb,
+ PrefetchHooks Function()> {
+ $$BookingEntityTableTableManager(
+ _$ComwellDatabase db, $BookingEntityTable table)
+ : super(TableManagerState(
+ db: db,
+ table: table,
+ createFilteringComposer: () =>
+ $$BookingEntityTableFilterComposer($db: db, $table: table),
+ createOrderingComposer: () =>
+ $$BookingEntityTableOrderingComposer($db: db, $table: table),
+ createComputedFieldComposer: () =>
+ $$BookingEntityTableAnnotationComposer($db: db, $table: table),
+ updateCompanionCallback: ({
+ Value<String> id = const Value.absent(),
+ Value<String> status = const Value.absent(),
+ Value<String> json = const Value.absent(),
+ Value<int> rowid = const Value.absent(),
+ }) =>
+ BookingEntityCompanion(
+ id: id,
+ status: status,
+ json: json,
+ rowid: rowid,
+ ),
+ createCompanionCallback: ({
+ required String id,
+ required String status,
+ required String json,
+ Value<int> rowid = const Value.absent(),
+ }) =>
+ BookingEntityCompanion.insert(
+ id: id,
+ status: status,
+ json: json,
+ rowid: rowid,
+ ),
+ withReferenceMapper: (p0) => p0
+ .map((e) => (e.readTable(table), BaseReferences(db, table, e)))
+ .toList(),
+ prefetchHooksCallback: null,
+ ));
+}
+
+typedef $$BookingEntityTableProcessedTableManager = ProcessedTableManager<
+ _$ComwellDatabase,
+ $BookingEntityTable,
+ BookingDb,
+ $$BookingEntityTableFilterComposer,
+ $$BookingEntityTableOrderingComposer,
+ $$BookingEntityTableAnnotationComposer,
+ $$BookingEntityTableCreateCompanionBuilder,
+ $$BookingEntityTableUpdateCompanionBuilder,
+ (
+ BookingDb,
+ BaseReferences<_$ComwellDatabase, $BookingEntityTable, BookingDb>
+ ),
+ BookingDb,
+ PrefetchHooks Function()>;
+typedef $$UserEntityTableCreateCompanionBuilder = UserEntityCompanion Function({
+ required String id,
+ required String json,
+ Value<int> rowid,
+});
+typedef $$UserEntityTableUpdateCompanionBuilder = UserEntityCompanion Function({
+ Value<String> id,
+ Value<String> json,
+ Value<int> rowid,
+});
+
+class $$UserEntityTableFilterComposer
+ extends Composer<_$ComwellDatabase, $UserEntityTable> {
+ $$UserEntityTableFilterComposer({
+ required super.$db,
+ required super.$table,
+ super.joinBuilder,
+ super.$addJoinBuilderToRootComposer,
+ super.$removeJoinBuilderFromRootComposer,
+ });
+ ColumnFilters<String> get id => $composableBuilder(
+ column: $table.id, builder: (column) => ColumnFilters(column));
+
+ ColumnFilters<String> get json => $composableBuilder(
+ column: $table.json, builder: (column) => ColumnFilters(column));
+}
+
+class $$UserEntityTableOrderingComposer
+ extends Composer<_$ComwellDatabase, $UserEntityTable> {
+ $$UserEntityTableOrderingComposer({
+ required super.$db,
+ required super.$table,
+ super.joinBuilder,
+ super.$addJoinBuilderToRootComposer,
+ super.$removeJoinBuilderFromRootComposer,
+ });
+ ColumnOrderings<String> get id => $composableBuilder(
+ column: $table.id, builder: (column) => ColumnOrderings(column));
+
+ ColumnOrderings<String> get json => $composableBuilder(
+ column: $table.json, builder: (column) => ColumnOrderings(column));
+}
+
+class $$UserEntityTableAnnotationComposer
+ extends Composer<_$ComwellDatabase, $UserEntityTable> {
+ $$UserEntityTableAnnotationComposer({
+ required super.$db,
+ required super.$table,
+ super.joinBuilder,
+ super.$addJoinBuilderToRootComposer,
+ super.$removeJoinBuilderFromRootComposer,
+ });
+ GeneratedColumn<String> get id =>
+ $composableBuilder(column: $table.id, builder: (column) => column);
+
+ GeneratedColumn<String> get json =>
+ $composableBuilder(column: $table.json, builder: (column) => column);
+}
+
+class $$UserEntityTableTableManager extends RootTableManager<
+ _$ComwellDatabase,
+ $UserEntityTable,
+ UserDb,
+ $$UserEntityTableFilterComposer,
+ $$UserEntityTableOrderingComposer,
+ $$UserEntityTableAnnotationComposer,
+ $$UserEntityTableCreateCompanionBuilder,
+ $$UserEntityTableUpdateCompanionBuilder,
+ (UserDb, BaseReferences<_$ComwellDatabase, $UserEntityTable, UserDb>),
+ UserDb,
+ PrefetchHooks Function()> {
+ $$UserEntityTableTableManager(_$ComwellDatabase db, $UserEntityTable table)
+ : super(TableManagerState(
+ db: db,
+ table: table,
+ createFilteringComposer: () =>
+ $$UserEntityTableFilterComposer($db: db, $table: table),
+ createOrderingComposer: () =>
+ $$UserEntityTableOrderingComposer($db: db, $table: table),
+ createComputedFieldComposer: () =>
+ $$UserEntityTableAnnotationComposer($db: db, $table: table),
+ updateCompanionCallback: ({
+ Value<String> id = const Value.absent(),
+ Value<String> json = const Value.absent(),
+ Value<int> rowid = const Value.absent(),
+ }) =>
+ UserEntityCompanion(
+ id: id,
+ json: json,
+ rowid: rowid,
+ ),
+ createCompanionCallback: ({
+ required String id,
+ required String json,
+ Value<int> rowid = const Value.absent(),
+ }) =>
+ UserEntityCompanion.insert(
+ id: id,
+ json: json,
+ rowid: rowid,
+ ),
+ withReferenceMapper: (p0) => p0
+ .map((e) => (e.readTable(table), BaseReferences(db, table, e)))
+ .toList(),
+ prefetchHooksCallback: null,
+ ));
+}
+
+typedef $$UserEntityTableProcessedTableManager = ProcessedTableManager<
+ _$ComwellDatabase,
+ $UserEntityTable,
+ UserDb,
+ $$UserEntityTableFilterComposer,
+ $$UserEntityTableOrderingComposer,
+ $$UserEntityTableAnnotationComposer,
+ $$UserEntityTableCreateCompanionBuilder,
+ $$UserEntityTableUpdateCompanionBuilder,
+ (UserDb, BaseReferences<_$ComwellDatabase, $UserEntityTable, UserDb>),
+ UserDb,
+ PrefetchHooks Function()>;
+
+class $ComwellDatabaseManager {
+ final _$ComwellDatabase _db;
+ $ComwellDatabaseManager(this._db);
+ $$BookingEntityTableTableManager get bookingEntity =>
+ $$BookingEntityTableTableManager(_db, _db.bookingEntity);
+ $$UserEntityTableTableManager get userEntity =>
+ $$UserEntityTableTableManager(_db, _db.userEntity);
+}
diff --git a/comwell_key_app/lib/.generated/database/daos/bookings_dao.g.dart b/comwell_key_app/lib/.generated/database/daos/bookings_dao.g.dart
new file mode 100644
index 00000000..df6dbcde
--- /dev/null
+++ b/comwell_key_app/lib/.generated/database/daos/bookings_dao.g.dart
@@ -0,0 +1,8 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of '../../../database/daos/bookings_dao.dart';
+
+// ignore_for_file: type=lint
+mixin _$BookingsDaoMixin on DatabaseAccessor<ComwellDatabase> {
+ $BookingEntityTable get bookingEntity => attachedDatabase.bookingEntity;
+}
diff --git a/comwell_key_app/lib/.generated/database/daos/user_dao.g.dart b/comwell_key_app/lib/.generated/database/daos/user_dao.g.dart
new file mode 100644
index 00000000..5fbc4332
--- /dev/null
+++ b/comwell_key_app/lib/.generated/database/daos/user_dao.g.dart
@@ -0,0 +1,8 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of '../../../database/daos/user_dao.dart';
+
+// ignore_for_file: type=lint
+mixin _$UserDAOMixin on DatabaseAccessor<ComwellDatabase> {
+ $UserEntityTable get userEntity => attachedDatabase.userEntity;
+}
diff --git a/comwell_key_app/lib/.generated/overview/models/booking.g.dart b/comwell_key_app/lib/.generated/overview/models/booking.g.dart
new file mode 100644
index 00000000..f1763483
--- /dev/null
+++ b/comwell_key_app/lib/.generated/overview/models/booking.g.dart
@@ -0,0 +1,50 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of '../../../overview/models/booking.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+Booking _$BookingFromJson(Map<String, dynamic> json) => Booking(
+ id: json['id'] as String,
+ userId: json['userId'] as String,
+ roomNumber: json['roomNumber'] as String,
+ startDate: DateTime.parse(json['startDate'] as String),
+ endDate: DateTime.parse(json['endDate'] as String),
+ status: $enumDecode(_$BookingStatusEnumMap, json['status']),
+ image: json['image'] as String,
+ hotelName: json['hotelName'] as String,
+ roomType: json['roomType'] as String,
+ children: (json['children'] as num).toInt(),
+ adults: (json['adults'] as num).toInt(),
+ hotelCode: json['hotelCode'] as String,
+ booker: json['booker'] as String,
+ bookingDate: DateTime.parse(json['bookingDate'] as String),
+ paymentDetails: PaymentDetails.fromJson(
+ json['paymentDetails'] as Map<String, dynamic>),
+ );
+
+Map<String, dynamic> _$BookingToJson(Booking instance) => <String, dynamic>{
+ 'id': instance.id,
+ 'userId': instance.userId,
+ 'roomNumber': instance.roomNumber,
+ 'startDate': instance.startDate.toIso8601String(),
+ 'endDate': instance.endDate.toIso8601String(),
+ 'status': _$BookingStatusEnumMap[instance.status]!,
+ 'image': instance.image,
+ 'hotelName': instance.hotelName,
+ 'hotelCode': instance.hotelCode,
+ 'roomType': instance.roomType,
+ 'adults': instance.adults,
+ 'children': instance.children,
+ 'booker': instance.booker,
+ 'bookingDate': instance.bookingDate.toIso8601String(),
+ 'paymentDetails': instance.paymentDetails,
+ };
+
+const _$BookingStatusEnumMap = {
+ BookingStatus.current: 'current',
+ BookingStatus.past: 'past',
+ BookingStatus.cancelled: 'cancelled',
+};
diff --git a/comwell_key_app/lib/.generated/overview/models/bookings.g.dart b/comwell_key_app/lib/.generated/overview/models/bookings.g.dart
new file mode 100644
index 00000000..70ab5c27
--- /dev/null
+++ b/comwell_key_app/lib/.generated/overview/models/bookings.g.dart
@@ -0,0 +1,25 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of '../../../overview/models/bookings.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+Bookings _$BookingsFromJson(Map<String, dynamic> json) => Bookings(
+ current: (json['current'] as List<dynamic>)
+ .map((e) => Booking.fromJson(e as Map<String, dynamic>))
+ .toList(),
+ past: (json['past'] as List<dynamic>)
+ .map((e) => Booking.fromJson(e as Map<String, dynamic>))
+ .toList(),
+ cancelled: (json['cancelled'] as List<dynamic>)
+ .map((e) => Booking.fromJson(e as Map<String, dynamic>))
+ .toList(),
+ );
+
+Map<String, dynamic> _$BookingsToJson(Bookings instance) => <String, dynamic>{
+ 'current': instance.current,
+ 'past': instance.past,
+ 'cancelled': instance.cancelled,
+ };
diff --git a/comwell_key_app/lib/.generated/overview/models/payment_details.g.dart b/comwell_key_app/lib/.generated/overview/models/payment_details.g.dart
new file mode 100644
index 00000000..0a81fbba
--- /dev/null
+++ b/comwell_key_app/lib/.generated/overview/models/payment_details.g.dart
@@ -0,0 +1,33 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of '../../../overview/models/payment_details.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+PaymentDetails _$PaymentDetailsFromJson(Map<String, dynamic> json) =>
+ PaymentDetails(
+ cardNumber: json['cardNumber'] as String,
+ cardHolder: json['cardHolder'] as String,
+ expiryDate: json['expiryDate'] as String?,
+ cvc: json['cvc'] as String?,
+ cardType: $enumDecode(_$CardTypeEnumMap, json['cardType']),
+ cardName: json['cardName'] as String?,
+ );
+
+Map<String, dynamic> _$PaymentDetailsToJson(PaymentDetails instance) =>
+ <String, dynamic>{
+ 'cardNumber': instance.cardNumber,
+ 'cardHolder': instance.cardHolder,
+ 'expiryDate': instance.expiryDate,
+ 'cvc': instance.cvc,
+ 'cardType': _$CardTypeEnumMap[instance.cardType]!,
+ 'cardName': instance.cardName,
+ };
+
+const _$CardTypeEnumMap = {
+ CardType.visa: 'visa',
+ CardType.mastercard: 'mastercard',
+ CardType.maestro: 'maestro',
+};
diff --git a/comwell_key_app/lib/.generated/profile_settings/model/user.g.dart b/comwell_key_app/lib/.generated/profile_settings/model/user.g.dart
new file mode 100644
index 00000000..6c98b890
--- /dev/null
+++ b/comwell_key_app/lib/.generated/profile_settings/model/user.g.dart
@@ -0,0 +1,31 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of '../../../profile_settings/model/user.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+User _$UserFromJson(Map<String, dynamic> json) => User(
+ id: json['id'] as String,
+ shopperReference: json['shopperReference'] as String?,
+ firstName: json['firstName'] as String,
+ lastName: json['lastName'] as String,
+ countryCode: json['countryCode'] as String,
+ phone: json['phone'] as String,
+ email: json['email'] as String,
+ address: Address.fromJson(json['address'] as Map<String, dynamic>),
+ birthday: DateTime.parse(json['birthday'] as String),
+ );
+
+Map<String, dynamic> _$UserToJson(User instance) => <String, dynamic>{
+ 'id': instance.id,
+ 'firstName': instance.firstName,
+ 'lastName': instance.lastName,
+ 'countryCode': instance.countryCode,
+ 'phone': instance.phone,
+ 'email': instance.email,
+ 'address': instance.address,
+ 'birthday': instance.birthday.toIso8601String(),
+ 'shopperReference': instance.shopperReference,
+ };
diff --git a/comwell_key_app/lib/.generated/services/adyen/adyen_line_item.g.dart b/comwell_key_app/lib/.generated/services/adyen/adyen_line_item.g.dart
index 594dc84c..68228837 100644
--- a/comwell_key_app/lib/.generated/services/adyen/adyen_line_item.g.dart
+++ b/comwell_key_app/lib/.generated/services/adyen/adyen_line_item.g.dart
@@ -21,13 +21,15 @@ AdyenLineItem _$AdyenLineItemFromJson(Map<String, dynamic> json) =>
Map<String, dynamic> _$AdyenLineItemToJson(AdyenLineItem instance) =>
<String, dynamic>{
- 'quantity': instance.quantity,
- 'amountExcludingTax': instance.amountExcludingTax,
- 'taxPercentage': instance.taxPercentage,
- 'description': instance.description,
- 'id': instance.id,
- 'taxAmount': instance.taxAmount,
- 'amountIncludingTax': instance.amountIncludingTax,
- 'productUrl': instance.productUrl,
- 'imageUrl': instance.imageUrl,
+ if (instance.quantity case final value?) 'quantity': value,
+ if (instance.amountExcludingTax case final value?)
+ 'amountExcludingTax': value,
+ if (instance.taxPercentage case final value?) 'taxPercentage': value,
+ if (instance.description case final value?) 'description': value,
+ if (instance.id case final value?) 'id': value,
+ if (instance.taxAmount case final value?) 'taxAmount': value,
+ if (instance.amountIncludingTax case final value?)
+ 'amountIncludingTax': value,
+ if (instance.productUrl case final value?) 'productUrl': value,
+ if (instance.imageUrl case final value?) 'imageUrl': value,
};
diff --git a/comwell_key_app/lib/common/const.dart b/comwell_key_app/lib/common/const.dart
index 5f1fb949..c3d6f7c7 100644
--- a/comwell_key_app/lib/common/const.dart
+++ b/comwell_key_app/lib/common/const.dart
@@ -6,4 +6,4 @@ const hasKey = 'hasKey';
// Adyen
class AdyenConstants {
static const merchantAccount = "ComwellHotelsECOM";
-}
+}
\ No newline at end of file
diff --git a/comwell_key_app/lib/database/comwell_db.dart b/comwell_key_app/lib/database/comwell_db.dart
new file mode 100644
index 00000000..df65458b
--- /dev/null
+++ b/comwell_key_app/lib/database/comwell_db.dart
@@ -0,0 +1,81 @@
+import 'dart:io';
+
+import 'package:comwell_key_app/database/tables/booking_table.dart';
+import 'package:comwell_key_app/database/tables/user_table.dart';
+import 'package:drift/drift.dart';
+import 'package:drift/native.dart';
+import 'package:flutter_secure_storage/flutter_secure_storage.dart';
+import 'package:path/path.dart' as p;
+import 'package:path_provider/path_provider.dart';
+import 'package:sqlcipher_flutter_libs/sqlcipher_flutter_libs.dart';
+import 'package:sqlite3/open.dart';
+import 'package:sqlite3/sqlite3.dart';
+import 'package:uuid/uuid.dart' as uuid;
+
+import 'daos/bookings_dao.dart';
+import 'daos/user_dao.dart';
+
+part '../.generated/database/comwell_db.g.dart';
+
+const secureStorage = FlutterSecureStorage();
+
+@DriftDatabase(
+ tables: [BookingEntity, UserEntity], daos: [BookingsDao, UserDAO])
+class ComwellDatabase extends _$ComwellDatabase {
+ ComwellDatabase() : super(_openDatabase()) {
+ deleteDatabase();
+ }
+
+ @override
+ int get schemaVersion => 1;
+
+ @override
+ MigrationStrategy get migration => destructiveFallback;
+
+ Future<void> deleteDatabase() async {
+ final supportDir = await getApplicationSupportDirectory();
+ final databaseDir = File("${supportDir.path}/app.db.enc");
+ final exists = await databaseDir.exists();
+ if (exists) {
+ await databaseDir.delete();
+ }
+ }
+}
+
+Future<String> getCipher() async {
+ final cipher = await secureStorage.read(key: "sql_cipher");
+ if (cipher == null || cipher.isEmpty) {
+ final newCipher =
+ const uuid.Uuid().v4obj().toString(); //.uuid.replaceAll("-", "");
+ await secureStorage.write(key: "sql_cipher", value: newCipher);
+ } else {
+ return cipher;
+ }
+
+ return getCipher();
+}
+
+QueryExecutor _openDatabase() {
+ return LazyDatabase(() async {
+ final path = await getApplicationSupportDirectory();
+ final file = File(p.join(path.path, "app.db.enc"));
+ final cipher = await getCipher();
+ Future<void> isolateSetup() async {
+ await applyWorkaroundToOpenSqlCipherOnOldAndroidVersions();
+ open.overrideFor(OperatingSystem.android, openCipherOnAndroid);
+ }
+
+ void setup(Database db) {
+ final result = db.select("pragma cipher_version");
+ if (result.isEmpty) {
+ throw UnsupportedError(
+ "This database needs to run with SQLCipher, but that library is unavailable");
+ }
+ db.execute("pragma key = \"$cipher\"");
+ db.execute("select count(*) from sqlite_master");
+ }
+
+ return NativeDatabase.createInBackground(file,
+ isolateSetup: isolateSetup, setup: setup);
+ });
+}
diff --git a/comwell_key_app/lib/database/daos/bookings_dao.dart b/comwell_key_app/lib/database/daos/bookings_dao.dart
new file mode 100644
index 00000000..a1a3cc48
--- /dev/null
+++ b/comwell_key_app/lib/database/daos/bookings_dao.dart
@@ -0,0 +1,69 @@
+import 'dart:convert';
+
+import 'package:comwell_key_app/database/comwell_db.dart';
+import 'package:comwell_key_app/overview/models/bookings.dart';
+import 'package:comwell_key_app/utils/json.dart';
+import 'package:drift/drift.dart';
+
+import '../../overview/models/booking.dart';
+import '../tables/booking_table.dart';
+
+part '../../.generated/database/daos/bookings_dao.g.dart';
+
+@DriftAccessor(tables: [BookingEntity])
+class BookingsDao extends DatabaseAccessor<ComwellDatabase>
+ with _$BookingsDaoMixin {
+ BookingsDao(super.attachedDatabase);
+
+ Future<Iterable<BookingDb>> getBookings() {
+ return bookingEntity.all().get();
+ }
+
+ Future<void> insert(Iterable<Booking> bookings, BookingStatus status) async {
+ final entities = bookings.map((booking) {
+ final json = jsonEncode(booking.toJson());
+ return BookingEntityCompanion.insert(
+ id: booking.id, json: json, status: status.toString());
+ });
+ await batch((batch) => batch.insertAll(bookingEntity, entities));
+ }
+
+ Future<void> insertBookings(Bookings bookings) async {
+ await insert(bookings.current, BookingStatus.current);
+ await insert(bookings.past, BookingStatus.past);
+ await insert(bookings.cancelled, BookingStatus.cancelled);
+ }
+
+ Stream<Iterable<Booking>> watchBookingsByStatus(BookingStatus status) {
+ return (select(bookingEntity)
+ ..where((entity) => entity.status.equals(status.toString())))
+ .watch()
+ .map((entities) {
+ return entities.map((entity) {
+ final json = jsonDecode(entity.json) as Json;
+ return Booking.fromJson(json);
+ });
+ });
+ }
+
+ Stream<Bookings> watchBookings() {
+ return (select(bookingEntity)).watch().map((entities) {
+ final current = entities.where((ent) =>
+ ent.status == BookingStatus.current.toString());
+ final past = entities.where((ent) =>
+ ent.status == BookingStatus.past.toString());
+ final cancelled = entities.where((ent) =>
+ ent.status == BookingStatus.cancelled.toString());
+ return Bookings(current: _entityToBooking(current),
+ past: _entityToBooking(past),
+ cancelled: _entityToBooking(cancelled));
+ });
+ }
+
+ List<Booking> _entityToBooking(Iterable<BookingDb> entities) {
+ return entities.map((entity) {
+ final json = jsonDecode(entity.json) as Json;
+ return Booking.fromJson(json);
+ }).toList();
+ }
+}
diff --git a/comwell_key_app/lib/database/daos/user_dao.dart b/comwell_key_app/lib/database/daos/user_dao.dart
new file mode 100644
index 00000000..0b1bf0db
--- /dev/null
+++ b/comwell_key_app/lib/database/daos/user_dao.dart
@@ -0,0 +1,30 @@
+import 'dart:convert';
+
+import 'package:comwell_key_app/database/comwell_db.dart';
+import 'package:comwell_key_app/profile_settings/model/user.dart';
+import 'package:comwell_key_app/utils/json.dart';
+import 'package:drift/drift.dart';
+
+import '../tables/user_table.dart';
+
+part '../../.generated/database/daos/user_dao.g.dart';
+
+@DriftAccessor(tables: [UserEntity])
+class UserDAO extends DatabaseAccessor<ComwellDatabase> with _$UserDAOMixin {
+ UserDAO(super.attachedDatabase);
+
+ Future<void> saveUser(User user) async {
+ final json = jsonEncode(user.toJson());
+ final insertOp = UserEntityCompanion.insert(id: user.id, json: json);
+ await (update(userEntity)..where((table) => table.id.equals(user.id)))
+ .write(insertOp);
+ }
+
+ Stream<User> watchUser() {
+ return (select(userEntity).watch()).map((users) {
+ final userTable = users.first;
+ final json = jsonDecode(userTable.json) as Json;
+ return User.fromJson(json);
+ });
+ }
+}
diff --git a/comwell_key_app/lib/database/tables/booking_table.dart b/comwell_key_app/lib/database/tables/booking_table.dart
new file mode 100644
index 00000000..bf612393
--- /dev/null
+++ b/comwell_key_app/lib/database/tables/booking_table.dart
@@ -0,0 +1,8 @@
+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
diff --git a/comwell_key_app/lib/database/tables/user_table.dart b/comwell_key_app/lib/database/tables/user_table.dart
new file mode 100644
index 00000000..b5d6c0a7
--- /dev/null
+++ b/comwell_key_app/lib/database/tables/user_table.dart
@@ -0,0 +1,7 @@
+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
diff --git a/comwell_key_app/lib/overview/models/booking.dart b/comwell_key_app/lib/overview/models/booking.dart
index 4bdf507e..d1c89c38 100644
--- a/comwell_key_app/lib/overview/models/booking.dart
+++ b/comwell_key_app/lib/overview/models/booking.dart
@@ -1,6 +1,11 @@
import 'package:comwell_key_app/overview/models/payment_details.dart';
+import 'package:comwell_key_app/utils/json.dart';
import 'package:equatable/equatable.dart';
+import 'package:json_annotation/json_annotation.dart';
+part '../../.generated/overview/models/booking.g.dart';
+
+@JsonSerializable()
class Booking extends Equatable {
final String id;
final String userId;
@@ -18,7 +23,6 @@ class Booking extends Equatable {
final DateTime bookingDate;
final PaymentDetails paymentDetails;
-
const Booking({
required this.id,
required this.userId,
@@ -37,57 +41,9 @@ class Booking extends Equatable {
required this.paymentDetails,
});
- factory Booking.fromJson(dynamic json) {
- return Booking(
- id: json['id'] as String,
- userId: json['userId'] as String,
- roomNumber: json['roomNumber'] as String,
- startDate: DateTime.parse(json['startDate'] as String),
- endDate: DateTime.parse(json['endDate'] as String),
- status: _parseBookingStatus(json['status'] as String),
- image: json['image'] as String,
- hotelName: json['hotelName'] as String,
- roomType: json['roomType'] as String,
- children: json['children'] as int,
- adults: json['adults'] as int,
- hotelCode: json['hotelCode'] as String,
- booker: json['booker'] as String,
- bookingDate: DateTime.parse(json['bookingDate'] as String),
- paymentDetails: PaymentDetails.fromJson(json['paymentDetails'] as Map<String, dynamic>),
- );
- }
+ factory Booking.fromJson(Json json) => _$BookingFromJson(json);
- Map<String, dynamic> toJson() {
- return {
- 'id': id,
- 'userId': userId,
- 'roomId': roomNumber,
- 'startDate': startDate.toIso8601String(),
- 'endDate': endDate.toIso8601String(),
- 'status': status.toString(),
- 'image': image,
- 'hotelName': hotelName,
- 'roomType': roomType,
- 'adults': adults,
- 'children': children,
- 'hotelCode': hotelCode,
- 'booker': booker,
- 'bookingDate': bookingDate.toIso8601String(),
- };
- }
-
- static BookingStatus _parseBookingStatus(String status) {
- switch (status) {
- case 'current':
- return BookingStatus.current;
- case 'past':
- return BookingStatus.past;
- case 'cancelled':
- return BookingStatus.cancelled;
- default:
- throw Exception('Unknown booking status: $status');
- }
- }
+ Json toJson() => _$BookingToJson(this);
@override
List<Object?> get props => [
diff --git a/comwell_key_app/lib/overview/models/bookings.dart b/comwell_key_app/lib/overview/models/bookings.dart
index 82b81753..0d3008b2 100644
--- a/comwell_key_app/lib/overview/models/bookings.dart
+++ b/comwell_key_app/lib/overview/models/bookings.dart
@@ -1,6 +1,11 @@
import 'package:comwell_key_app/overview/models/booking.dart';
+import 'package:comwell_key_app/utils/json.dart';
import 'package:equatable/equatable.dart';
+import 'package:json_annotation/json_annotation.dart';
+part '../../.generated/overview/models/bookings.g.dart';
+
+@JsonSerializable()
class Bookings extends Equatable {
final List<Booking> current;
final List<Booking> past;
@@ -12,14 +17,10 @@ class Bookings extends Equatable {
required this.cancelled,
});
- factory Bookings.fromJson(Map<String, dynamic> json) {
- return Bookings(
- current: (json['current'] as List<dynamic>).map<Booking>((dynamic e) => Booking.fromJson(e)).toList(),
- past: (json['past'] as List<dynamic>).map<Booking>((dynamic e) => Booking.fromJson(e)).toList(),
- cancelled: (json['cancelled'] as List<dynamic>).map<Booking>((dynamic e) => Booking.fromJson(e)).toList(),
- );
- }
-
+ factory Bookings.fromJson(Json json) => _$BookingsFromJson(json);
+
+ Json toJson() => _$BookingsToJson(this);
+
@override
List<Object> get props => [current, past, cancelled];
}
\ No newline at end of file
diff --git a/comwell_key_app/lib/overview/models/payment_details.dart b/comwell_key_app/lib/overview/models/payment_details.dart
index 7bcdc92a..6d05ca6d 100644
--- a/comwell_key_app/lib/overview/models/payment_details.dart
+++ b/comwell_key_app/lib/overview/models/payment_details.dart
@@ -1,5 +1,10 @@
+import 'package:comwell_key_app/utils/json.dart';
import 'package:equatable/equatable.dart';
+import 'package:json_annotation/json_annotation.dart';
+part '../../.generated/overview/models/payment_details.g.dart';
+
+@JsonSerializable()
class PaymentDetails extends Equatable {
final String cardNumber;
final String cardHolder;
@@ -17,26 +22,9 @@ class PaymentDetails extends Equatable {
this.cardName,
});
- factory PaymentDetails.fromJson(dynamic json) {
- return PaymentDetails(
- cardNumber: json['cardNumber'] as String,
- cardHolder: json['cardHolder'] as String,
- expiryDate: json['expiryDate'] as String,
- cvc: json['cvc'] as String,
- cardType: CardType.fromString(json['cardType'] as String),
- cardName: json['cardName'] as String,
- );
- }
+ factory PaymentDetails.fromJson(Json json) => _$PaymentDetailsFromJson(json);
- Map<String, dynamic> toJson() {
- return {
- 'cardNumber': cardNumber,
- 'cardHolder': cardHolder,
- 'expiryDate': expiryDate,
- 'cvc': cvc,
- 'cardType': cardType.toString(),
- };
- }
+ Map<String, dynamic> toJson() => _$PaymentDetailsToJson(this);
@override
diff --git a/comwell_key_app/lib/overview/repository/overview_repository.dart b/comwell_key_app/lib/overview/repository/overview_repository.dart
index e9357f8c..61a98ec4 100644
--- a/comwell_key_app/lib/overview/repository/overview_repository.dart
+++ b/comwell_key_app/lib/overview/repository/overview_repository.dart
@@ -1,16 +1,21 @@
+import 'package:comwell_key_app/database/comwell_db.dart';
import 'package:comwell_key_app/overview/models/booking.dart';
import 'package:comwell_key_app/overview/models/bookings.dart';
import 'package:comwell_key_app/services/api.dart';
+import 'package:comwell_key_app/utils/locator.dart';
class OverviewRepository {
final api = Api();
+ final database = locator<ComwellDatabase>();
OverviewRepository();
Future<Bookings> fetchAllBookingsForUser(String userId) async {
//final response = await api.fetchAllBookingsForUser(userId);
//if (response != null) {
- return Bookings.fromJson(response);
+ final bookings = Bookings.fromJson(response);
+ await database.bookingsDao.insertBookings(bookings);
+ return bookings;
// } else {
// throw Exception('Failed to fetch bookings');
// }
diff --git a/comwell_key_app/lib/pregistration/pregistration_repository.dart b/comwell_key_app/lib/pregistration/pregistration_repository.dart
index 713e8ffe..b96c58c2 100644
--- a/comwell_key_app/lib/pregistration/pregistration_repository.dart
+++ b/comwell_key_app/lib/pregistration/pregistration_repository.dart
@@ -21,7 +21,7 @@ class PreregistrationRepository {
Future<Iterable<StoredPaymentMethod>> getPaymentMethods() async {
final user = await profileSettingsRepository.fetchProfileSettings();
if (user == null) throw Exception("User not logged in");
- final response = await api.getPaymentMethods(user.shopperReference);
+ final response = await api.getPaymentMethods(user.shopperReference ?? "");
return response.data!.storedPaymentMethods;
}
diff --git a/comwell_key_app/lib/profile_settings/model/user.dart b/comwell_key_app/lib/profile_settings/model/user.dart
index f505cc8b..786da2c4 100644
--- a/comwell_key_app/lib/profile_settings/model/user.dart
+++ b/comwell_key_app/lib/profile_settings/model/user.dart
@@ -1,5 +1,11 @@
import 'package:comwell_key_app/profile_settings/model/address.dart';
+import 'package:json_annotation/json_annotation.dart';
+import '../../utils/json.dart';
+
+part '../../.generated/profile_settings/model/user.g.dart';
+
+@JsonSerializable()
class User {
final String id;
final String firstName;
@@ -9,7 +15,7 @@ class User {
final String email;
final Address address;
final DateTime birthday;
- final String shopperReference;
+ final String? shopperReference;
User({
required this.id,
@@ -23,32 +29,9 @@ class User {
required this.birthday,
});
- factory User.fromJson(dynamic json) {
- return User(
- id: json['id'] as String,
- firstName: json['firstName'] as String,
- lastName: json['lastName'] as String,
- countryCode: json['countryCode'] as String,
- shopperReference: json["shopperReference"] as String? ?? "",
- phone: json['phone'] as String,
- email: json['email'] as String,
- address: Address.fromJson(json['address'] as Map<String, dynamic>),
- birthday: DateTime.parse(json['birthday'] as String),
- );
- }
+ factory User.fromJson(Json json) => _$UserFromJson(json);
- Map<String, dynamic> toJson() {
- return {
- 'id': id,
- 'firstName': firstName,
- 'lastName': lastName,
- 'phone': phone,
- 'email': email,
- 'shopperReference': shopperReference,
- 'address': address.toJson(),
- 'birthday': birthday.toIso8601String(),
- };
- }
+ Json toJson() => _$UserToJson(this);
User copyWith({
String? id,
diff --git a/comwell_key_app/lib/profile_settings/repostiory/profile_settings_repository.dart b/comwell_key_app/lib/profile_settings/repostiory/profile_settings_repository.dart
index 734d0226..5f929183 100644
--- a/comwell_key_app/lib/profile_settings/repostiory/profile_settings_repository.dart
+++ b/comwell_key_app/lib/profile_settings/repostiory/profile_settings_repository.dart
@@ -1,21 +1,27 @@
+import 'package:comwell_key_app/database/comwell_db.dart';
import 'package:comwell_key_app/profile_settings/model/user.dart';
import 'package:comwell_key_app/services/api.dart';
import 'dart:convert';
+import 'package:comwell_key_app/utils/json.dart';
+import 'package:comwell_key_app/utils/locator.dart';
+
class ProfileSettingsRepository {
final Api api = Api();
+ final db = locator<ComwellDatabase>();
Future<User?> fetchProfileSettings() async {
final userJson = await api.fetchProfileSettings();
if (userJson != null) {
- return User.fromJson(jsonDecode(userJson as String));
+ final user = User.fromJson(jsonDecode(userJson as String) as Json);
+ db.userDAO.saveUser(user);
+ return user;
}
return null;
}
Future<void> updateUser(User updatedUser) async {
return api.updateUser(updatedUser);
-
}
Future<void> deleteProfile() {
diff --git a/comwell_key_app/lib/utils/locator.dart b/comwell_key_app/lib/utils/locator.dart
index b43caf86..05fbc1ee 100644
--- a/comwell_key_app/lib/utils/locator.dart
+++ b/comwell_key_app/lib/utils/locator.dart
@@ -1,4 +1,5 @@
import 'package:comwell_key_app/authentication/authentication_repository.dart';
+import 'package:comwell_key_app/database/comwell_db.dart';
import 'package:comwell_key_app/home/home_repository.dart';
import 'package:comwell_key_app/key/repository/key_repository.dart';
import 'package:comwell_key_app/overview/repository/overview_repository.dart';
@@ -28,5 +29,6 @@ void setupLocator() {
locator.registerFactory<ProfileRepository>(() => ProfileRepository());
locator.registerFactory<PreregistrationRepository>(
() => PreregistrationRepository());
+ locator.registerSingleton<ComwellDatabase>(ComwellDatabase());
}
}
diff --git a/comwell_key_app/linux/flutter/generated_plugin_registrant.cc b/comwell_key_app/linux/flutter/generated_plugin_registrant.cc
index d0e7f797..743b08c1 100644
--- a/comwell_key_app/linux/flutter/generated_plugin_registrant.cc
+++ b/comwell_key_app/linux/flutter/generated_plugin_registrant.cc
@@ -7,9 +7,13 @@
#include "generated_plugin_registrant.h"
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
+#include <sqlcipher_flutter_libs/sqlite3_flutter_libs_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);
+ g_autoptr(FlPluginRegistrar) sqlcipher_flutter_libs_registrar =
+ fl_plugin_registry_get_registrar_for_plugin(registry, "Sqlite3FlutterLibsPlugin");
+ sqlite3_flutter_libs_plugin_register_with_registrar(sqlcipher_flutter_libs_registrar);
}
diff --git a/comwell_key_app/linux/flutter/generated_plugins.cmake b/comwell_key_app/linux/flutter/generated_plugins.cmake
index b29e9ba0..9f8d1d42 100644
--- a/comwell_key_app/linux/flutter/generated_plugins.cmake
+++ b/comwell_key_app/linux/flutter/generated_plugins.cmake
@@ -4,6 +4,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_linux
+ sqlcipher_flutter_libs
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST
diff --git a/comwell_key_app/macos/Flutter/GeneratedPluginRegistrant.swift b/comwell_key_app/macos/Flutter/GeneratedPluginRegistrant.swift
index b0959ef0..361fda52 100644
--- a/comwell_key_app/macos/Flutter/GeneratedPluginRegistrant.swift
+++ b/comwell_key_app/macos/Flutter/GeneratedPluginRegistrant.swift
@@ -9,6 +9,7 @@ import device_info_plus
import flutter_secure_storage_macos
import path_provider_foundation
import shared_preferences_foundation
+import sqlcipher_flutter_libs
import webview_flutter_wkwebview
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
@@ -16,5 +17,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
+ Sqlite3FlutterLibsPlugin.register(with: registry.registrar(forPlugin: "Sqlite3FlutterLibsPlugin"))
FLTWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "FLTWebViewFlutterPlugin"))
}
diff --git a/comwell_key_app/pubspec.yaml b/comwell_key_app/pubspec.yaml
index dfc7947c..b5e23afe 100644
--- a/comwell_key_app/pubspec.yaml
+++ b/comwell_key_app/pubspec.yaml
@@ -42,6 +42,12 @@ dependencies:
country_code_picker: ^3.1.0
adyen_checkout: ^1.2.0
json_annotation: ^4.9.0
+ drift: ^2.23.1
+ sqlcipher_flutter_libs: ^0.6.4
+ uuid: ^4.5.1
+ sqlite3: ^2.6.0
+ path: ^1.9.0
+ path_provider: ^2.1.5
dev_dependencies:
flutter_test:
@@ -50,6 +56,7 @@ dev_dependencies:
change_app_package_name: ^1.3.0
build_runner: ^2.4.13
json_serializable: ^6.9.0
+ drift_dev: ^2.23.1
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
diff --git a/comwell_key_app/windows/flutter/generated_plugin_registrant.cc b/comwell_key_app/windows/flutter/generated_plugin_registrant.cc
index 8883006f..b2f4dc78 100644
--- a/comwell_key_app/windows/flutter/generated_plugin_registrant.cc
+++ b/comwell_key_app/windows/flutter/generated_plugin_registrant.cc
@@ -8,10 +8,13 @@
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
+#include <sqlcipher_flutter_libs/sqlite3_flutter_libs_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
+ Sqlite3FlutterLibsPluginRegisterWithRegistrar(
+ registry->GetRegistrarForPlugin("Sqlite3FlutterLibsPlugin"));
}
diff --git a/comwell_key_app/windows/flutter/generated_plugins.cmake b/comwell_key_app/windows/flutter/generated_plugins.cmake
index 6f183715..3904569f 100644
--- a/comwell_key_app/windows/flutter/generated_plugins.cmake
+++ b/comwell_key_app/windows/flutter/generated_plugins.cmake
@@ -5,6 +5,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_windows
permission_handler_windows
+ sqlcipher_flutter_libs
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST