diff --git a/evently/lib/evently_provider.dart b/evently/lib/evently_provider.dart index d8267b6ccc..0dcec1ace6 100644 --- a/evently/lib/evently_provider.dart +++ b/evently/lib/evently_provider.dart @@ -83,6 +83,13 @@ class EventlyProvider extends ChangeNotifier { String get location => _location; String get description => _description; + int? _id; + set setId(int id) { + _id = id; + } + + get id => _id; + set setStartDate(String value) { _startDate = value; notifyListeners(); @@ -358,7 +365,33 @@ class EventlyProvider extends ChangeNotifier { required VoidCallback onCompleted, required UploadStep uploadStep, }) async { - await repository.saveEvents(Events(step: uploadStep.toString(), eventName: eventName, hostName: hostName, thumbnail: thumbnail!)); + switch (uploadStep) { + case UploadStep.overView: + await repository.saveEvents(Events(step: uploadStep.toString(), eventName: eventName, hostName: hostName, thumbnail: thumbnail!)); + break; + case UploadStep.detail: + await repository.saveFromDetail(Events( + id: 1, + step: uploadStep.toString(), + eventName: eventName, + hostName: hostName, + thumbnail: thumbnail!, + startDate: startDate, + endDate: endDate, + startTime: startTime, + endTime: endTime, + location: location, + description: description, + )); + break; + case UploadStep.perks: + // TODO: Handle this case. + case UploadStep.price: + // TODO: Handle this case. + case UploadStep.none: + // TODO: Handle this case. + } + onCompleted(); } } diff --git a/evently/lib/repository/repository.dart b/evently/lib/repository/repository.dart index ef71a3076f..214dfbe9f9 100644 --- a/evently/lib/repository/repository.dart +++ b/evently/lib/repository/repository.dart @@ -90,6 +90,8 @@ abstract class Repository { /// Input: [key] the key of the value /// Output: [String] the value of the key dynamic getCacheDynamicType({required String key}); + + Future> saveFromDetail(Events events); } @LazySingleton(as: Repository) @@ -221,4 +223,17 @@ class RepositoryImp implements Repository { dynamic getCacheDynamicType({required String key}) { return localDataSource.getCacheDynamicType(key: key); } + + @override + Future> saveFromDetail(Events events) async { + try { + final bool result = await localDataSource.saveEventFromDetail(events: events); + if (!result) { + return Left(CacheFailure(LocaleKeys.get_error.tr())); + } + return Right(result); + } on Exception catch (_) { + return Left(CacheFailure(LocaleKeys.get_error.tr())); + } + } } diff --git a/evently/lib/screens/create_event.dart b/evently/lib/screens/create_event.dart index b50f5fc41e..0a95327c00 100644 --- a/evently/lib/screens/create_event.dart +++ b/evently/lib/screens/create_event.dart @@ -34,6 +34,12 @@ class _CreateEventState extends State { eventlyProvider.setEventName = createEventViewModel.events!.eventName; eventlyProvider.setHostName = createEventViewModel.events!.hostName; eventlyProvider.setThumbnail = createEventViewModel.events!.thumbnail; + eventlyProvider.setStartDate = createEventViewModel.events!.startDate; + eventlyProvider.setEndDate = createEventViewModel.events!.endDate; + eventlyProvider.setStartTime = createEventViewModel.events!.startTime; + eventlyProvider.setEndTime = createEventViewModel.events!.endTime; + eventlyProvider.setLocation = createEventViewModel.events!.location; + eventlyProvider.setDescription = createEventViewModel.events!.description; }); } diff --git a/evently/lib/screens/detail_screen.dart b/evently/lib/screens/detail_screen.dart index 8f6cb89e65..60a3631eb7 100644 --- a/evently/lib/screens/detail_screen.dart +++ b/evently/lib/screens/detail_screen.dart @@ -5,6 +5,8 @@ import 'package:evently/screens/custom_widgets/bottom_buttons.dart'; import 'package:evently/screens/custom_widgets/page_app_bar.dart'; import 'package:evently/screens/custom_widgets/step_labels.dart'; import 'package:evently/screens/custom_widgets/steps_indicator.dart'; +import 'package:evently/utils/enums.dart'; +import 'package:evently/utils/route_util.dart'; import 'package:evently/utils/space_utils.dart'; import 'package:evently/viewmodels/create_event_viewmodel.dart'; import 'package:evently/widgets/evently_text_field.dart'; @@ -162,7 +164,13 @@ class _DetailsScreenState extends State { onPressContinue: () { createEventViewModel.nextPage(); }, - onPressSaveDraft: () {}, + onPressSaveDraft: () { + final navigator = Navigator.of(context); + provider.saveAsDraft( + onCompleted: () => navigator.popUntil((route) => route.settings.name == RouteUtil.kRouteEventHub), + uploadStep: UploadStep.detail, + ); + }, isContinueEnable: provider.startDate.isNotEmpty && provider.endDate.isNotEmpty && provider.startTime.isNotEmpty && diff --git a/evently/lib/services/datasources/local_datasource.dart b/evently/lib/services/datasources/local_datasource.dart index 87fb13ad79..16c1f7576b 100644 --- a/evently/lib/services/datasources/local_datasource.dart +++ b/evently/lib/services/datasources/local_datasource.dart @@ -86,6 +86,9 @@ abstract class LocalDataSource { /// Input: [key] the key of the value /// Output: [String] the value of the key String getCacheString({required String key}); + + /// this method is used to save draft from + Future saveEventFromDetail({required Events events}); } @LazySingleton(as: LocalDataSource) @@ -214,4 +217,23 @@ class LocalDataSourceImpl extends LocalDataSource { void deleteCacheDynamic({required String key}) { cacheManager.deleteCacheDynamic(key: key); } + + @override + Future saveEventFromDetail({required Events events}) async { + try { + await database.eventsDao.updateNFTFromDetail( + events.startDate, + events.endDate, + events.startTime, + events.endTime, + events.location, + events.description, + events.id!, + events.step, + ); + return true; + } catch (e) { + throw CacheFailure(LocaleKeys.get_error.tr()); + } + } } diff --git a/evently/lib/services/third_party_services/database.g.dart b/evently/lib/services/third_party_services/database.g.dart index 3ae7cff4fa..6a349f3fe3 100644 --- a/evently/lib/services/third_party_services/database.g.dart +++ b/evently/lib/services/third_party_services/database.g.dart @@ -21,12 +21,14 @@ abstract class $AppDatabaseBuilderContract { class $FloorAppDatabase { /// Creates a database builder for a persistent database. /// Once a database is built, you should keep a reference to it and re-use it. - static $AppDatabaseBuilderContract databaseBuilder(String name) => _$AppDatabaseBuilder(name); + static $AppDatabaseBuilderContract databaseBuilder(String name) => + _$AppDatabaseBuilder(name); /// Creates a database builder for an in memory database. /// Information stored in an in memory database disappears when the process is killed. /// Once a database is built, you should keep a reference to it and re-use it. - static $AppDatabaseBuilderContract inMemoryDatabaseBuilder() => _$AppDatabaseBuilder(null); + static $AppDatabaseBuilderContract inMemoryDatabaseBuilder() => + _$AppDatabaseBuilder(null); } class _$AppDatabaseBuilder implements $AppDatabaseBuilderContract { @@ -52,7 +54,9 @@ class _$AppDatabaseBuilder implements $AppDatabaseBuilderContract { @override Future build() async { - final path = name != null ? await sqfliteDatabaseFactory.getDatabasePath(name!) : ':memory:'; + final path = name != null + ? await sqfliteDatabaseFactory.getDatabasePath(name!) + : ':memory:'; final database = _$AppDatabase(); database.database = await database.open( path, @@ -85,7 +89,8 @@ class _$AppDatabase extends AppDatabase { await callback?.onOpen?.call(database); }, onUpgrade: (database, startVersion, endVersion) async { - await MigrationAdapter.runMigrations(database, startVersion, endVersion, migrations); + await MigrationAdapter.runMigrations( + database, startVersion, endVersion, migrations); await callback?.onUpgrade?.call(database, startVersion, endVersion); }, @@ -193,7 +198,8 @@ class _$EventsDao extends EventsDao { @override Future delete(int id) async { - await _queryAdapter.queryNoReturn('DELETE FROM events WHERE id = ?1', arguments: [id]); + await _queryAdapter + .queryNoReturn('DELETE FROM events WHERE id = ?1', arguments: [id]); } @override @@ -205,9 +211,20 @@ class _$EventsDao extends EventsDao { String location, String description, int id, + String step, ) async { - await _queryAdapter.queryNoReturn('UPDATE events SET startDate = ?1, endDate= ?2, startTime = ?3, endTime = ?4,location = ?5, description = ?6 WHERE id = ?7', - arguments: [startDate, endDate, startTime, endTime, location, description, id]); + await _queryAdapter.queryNoReturn( + 'UPDATE events SET startDate = ?1, endDate= ?2, startTime = ?3, endTime = ?4,location = ?5, description = ?6, step = ?8 WHERE id = ?7', + arguments: [ + startDate, + endDate, + startTime, + endTime, + location, + description, + id, + step + ]); } @override @@ -215,7 +232,9 @@ class _$EventsDao extends EventsDao { String listOfPerks, int id, ) async { - await _queryAdapter.queryNoReturn('UPDATE events SET listOfPerks = ?1 WHERE id = ?2', arguments: [listOfPerks, id]); + await _queryAdapter.queryNoReturn( + 'UPDATE events SET listOfPerks = ?1 WHERE id = ?2', + arguments: [listOfPerks, id]); } @override @@ -225,11 +244,14 @@ class _$EventsDao extends EventsDao { String price, String isFreeDrops, ) async { - await _queryAdapter.queryNoReturn('UPDATE events SET numberOfTickets = ?2, price = ?3, isFreeDrops = ?4 WHERE id = ?1', arguments: [id, numberOfTickets, price, isFreeDrops]); + await _queryAdapter.queryNoReturn( + 'UPDATE events SET numberOfTickets = ?2, price = ?3, isFreeDrops = ?4 WHERE id = ?1', + arguments: [id, numberOfTickets, price, isFreeDrops]); } @override Future insertEvents(Events events) { - return _eventsInsertionAdapter.insertAndReturnId(events, OnConflictStrategy.abort); + return _eventsInsertionAdapter.insertAndReturnId( + events, OnConflictStrategy.abort); } } diff --git a/evently/lib/services/third_party_services/event_dao.dart b/evently/lib/services/third_party_services/event_dao.dart index 95bbcfe26e..33f424672b 100644 --- a/evently/lib/services/third_party_services/event_dao.dart +++ b/evently/lib/services/third_party_services/event_dao.dart @@ -15,7 +15,7 @@ abstract class EventsDao { @Query('DELETE FROM events WHERE id = :id') Future delete(int id); - @Query('UPDATE events SET startDate = :startDate, endDate= :endDate, startTime = :startTime, endTime = :endTime,location = :location, description = :description WHERE id = :id') + @Query('UPDATE events SET startDate = :startDate, endDate= :endDate, startTime = :startTime, endTime = :endTime,location = :location, description = :description, step = :step WHERE id = :id') Future updateNFTFromDetail( String startDate, String endDate, @@ -24,6 +24,7 @@ abstract class EventsDao { String location, String description, int id, + String step, ); @Query('UPDATE events SET listOfPerks = :listOfPerks WHERE id = :id')