Skip to content

Commit

Permalink
feat: database operation needed to work in app for draft and publish …
Browse files Browse the repository at this point in the history
…list
  • Loading branch information
AhsanRns committed May 17, 2024
1 parent cd077b4 commit 059a90d
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 25 deletions.
5 changes: 4 additions & 1 deletion evently/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,8 @@
"cookbook_not_found": "Cookbook nicht gefunden",
"loading": "Wird geladen ...",
"something_wrong": "Etwas ist schief gelaufen. Bitte versuchen Sie, die Anwendung neu zu starten.",
"get_error": "Entwurf konnte nicht abgerufen werden"
"get_error": "Entwurf konnte nicht abgerufen werden",
"delete_error": "Entwurf konnte nicht gelöscht werden",
"save_error": "Entwurf konnte nicht gespeichert werden",
"save_error": "Failed to save draft"
}
3 changes: 2 additions & 1 deletion evently/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@
"cookbook_not_found": "Cookbook not found",
"loading": "loading ...",
"something_wrong": "Something went wrong. Please try restarting the application.",
"get_error": "Failed to get draft"
"get_error": "Failed to get draft",
"delete_error": "Failed to delete draft"
}
4 changes: 3 additions & 1 deletion evently/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@
"cookbook_not_found": "Cookbook extraviado",
"loading": "cargando ...",
"something_wrong": "Algo salió mal. Intenta reiniciar la aplicación.",
"get_error": "No se pudo obtener el Plan Preliminar"
"get_error": "No se pudo obtener el Plan Preliminar",
"delete_error": "No se pudo eliminar el Plan Preliminar",
"save_error": "No se pudo guardar el Plan Preliminar"
}
4 changes: 3 additions & 1 deletion evently/i18n/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@
"cookbook_not_found": "Cookbook не найден",
"loading": "cargando ...",
"something_wrong": "Что-то пошло не так. Попробуйте перезапустить приложение.",
"get_error": "Не удалось получить черновик"
"get_error": "Не удалось получить черновик",
"delete_error": "Не удалось удалить черновик",
"save_error": "Не удалось сохранить черновик"
}
27 changes: 23 additions & 4 deletions evently/lib/evently_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import 'package:flutter/widgets.dart';
import 'package:get_it/get_it.dart';
import 'package:injectable/injectable.dart';
import 'package:pylons_sdk/low_level.dart';

import 'services/third_party_services/quick_node.dart';

@LazySingleton()
Expand Down Expand Up @@ -218,7 +217,6 @@ class EventlyProvider extends ChangeNotifier {
setThumbnail = "$ipfsDomain/${fileUploadResponse.value?.cid}";
}

String currentUserName = "";
bool stripeAccountExists = false;

String? _cookbookId;
Expand All @@ -231,7 +229,6 @@ class EventlyProvider extends ChangeNotifier {
final sdkResponse = await PylonsWallet.instance.getProfile();

if (sdkResponse.success) {
currentUserName = sdkResponse.data!.username;
stripeAccountExists = sdkResponse.data!.stripeExists;

supportedDenomList = Denom.availableDenoms.where((Denom e) => sdkResponse.data!.supportedCoins.contains(e.symbol)).toList();
Expand Down Expand Up @@ -278,7 +275,7 @@ class EventlyProvider extends ChangeNotifier {
price: price.toString(),
listOfPerks: perks.join(','),
cookbookID: _cookbookId!,
recipeID: _recipeId,
recipeID: _recipeId, step: '',
);

final recipe = event.createRecipe(
Expand Down Expand Up @@ -331,4 +328,26 @@ class EventlyProvider extends ChangeNotifier {
navigatorKey.showMsg(message: response.error);
return false;
}

void initStore() {
_eventName = "";
_hostName = "";
_thumbnail = "";
_isOverviewEnable = false;

_startDate = "";
_endDate = "";
_startTime = "";
_endTime = "";
_location = "";
_description = "";
_selectedDenom = Denom.availableDenoms.first;

_isFreeDrop = FreeDrop.unselected;
_numberOfTickets = 0;
_price = 0;
_cookbookId = '';

notifyListeners();
}
}
2 changes: 2 additions & 0 deletions evently/lib/generated/locale_keys.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,7 @@ abstract class LocaleKeys {
static const loading = 'loading';
static const something_wrong = 'something_wrong';
static const get_error = 'get_error';
static const delete_error = 'delete_error';
static const save_error = 'save_error';

}
9 changes: 6 additions & 3 deletions evently/lib/models/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enum FreeDrop { yes, no, unselected }
class Events extends Equatable {
@primaryKey
final int? id;

final String recipeID;
final String eventName;
final String hostName;
final String thumbnail;
Expand All @@ -24,9 +24,11 @@ class Events extends Equatable {
final String listOfPerks;
final String isFreeDrops;
final String cookbookID;
final String recipeID;
final String step;

const Events({
this.id,

///* overview data
this.eventName = '',
this.hostName = '',
Expand All @@ -51,7 +53,7 @@ class Events extends Equatable {
///* other
this.cookbookID = '',
this.recipeID = '',
this.id,
required this.step,
});

factory Events.fromRecipe(Recipe recipe) {
Expand All @@ -69,6 +71,7 @@ class Events extends Equatable {
numberOfTickets: map[kNumberOfTickets]!,
price: map[kPrice]!,
listOfPerks: map[kPerks]!,
step: '',
);
}

Expand Down
7 changes: 3 additions & 4 deletions evently/lib/repository/repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ abstract class Repository {

/// This method will get the drafts List from the local database
/// Output: [List] returns that contains a number of [NFT]
Future<Either<Failure, List<Events>>> getEvents();
Future<Either<Failure, List<Events>>> getAllEvents();
}

@LazySingleton(as: Repository)
Expand Down Expand Up @@ -136,10 +136,9 @@ class RepositoryImp implements Repository {
}

@override
Future<Either<Failure, List<Events>>> getEvents() async {
Future<Either<Failure, List<Events>>> getAllEvents() async {
try {
final response = await localDataSource.getEvents();

final response = await localDataSource.getAllEvents();
return Right(response);
} on Exception catch (_) {
return Left(CacheFailure(LocaleKeys.something_wrong.tr()));
Expand Down
5 changes: 5 additions & 0 deletions evently/lib/screens/create_event.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:evently/evently_provider.dart';
import 'package:evently/screens/detail_screen.dart';
import 'package:evently/screens/host_view_ticket_preview.dart';
import 'package:evently/screens/overview_screen.dart';
Expand All @@ -23,6 +24,10 @@ class _CreateEventState extends State<CreateEvent> {
void initState() {
super.initState();

WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
context.read<EventlyProvider>().initStore();
});

createEventViewModel.init();
}

Expand Down
2 changes: 1 addition & 1 deletion evently/lib/screens/event_hub/event_hub_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class EventHubViewModel extends ChangeNotifier {
Future<void> getDraftsList() async {
final loading = LoadingProgress()..showLoadingWithProgress(message: LocaleKeys.loading.tr());

final getEventResponse = await repository.getEvents();
final getEventResponse = await repository.getAllEvents();

if (getEventResponse.isLeft()) {
loading.dismiss();
Expand Down
34 changes: 32 additions & 2 deletions evently/lib/services/datasources/local_datasource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ abstract class LocalDataSource {

/// This method will get the drafts List from the local database
/// Output: [List][NFT] returns the List of drafts
Future<List<Events>> getEvents();
Future<List<Events>> getAllEvents();

/// This method will delete draft from the local database
/// Input: [recipeID] the id of the draft which the user wants to delete
/// Output: [bool] returns whether the operation is successful or not
Future<bool> deleteEvents(int id);

/// This method will save the draft of the NFT
/// Input: [Events] the draft that will will be saved in database
/// Output: [int] returns id of the inserted document
Future<int> saveEvents(Events events);
}

@LazySingleton(as: LocalDataSource)
Expand Down Expand Up @@ -101,11 +111,31 @@ class LocalDataSourceImpl extends LocalDataSource {
}

@override
Future<List<Events>> getEvents() async {
Future<List<Events>> getAllEvents() async {
try {
return await database.eventsDao.findAllEvents();
} catch (e) {
throw CacheFailure(LocaleKeys.get_error.tr());
}
}

@override
Future<bool> deleteEvents(int id) async {
try {
await database.eventsDao.delete(id);
return true;
} catch (e) {
throw CacheFailure(LocaleKeys.delete_error.tr());
}
}

@override
Future<int> saveEvents(Events events) async {
try {
final result = await database.eventsDao.insertEvents(events);
return result;
} catch (e) {
throw LocaleKeys.save_error.tr();
}
}
}
59 changes: 53 additions & 6 deletions evently/lib/services/third_party_services/database.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion evently/lib/services/third_party_services/event_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:floor/floor.dart';

@dao
abstract class EventsDao {
@Query('SELECT * FROM events ORDER BY dateTime DESC')
@Query('SELECT * FROM events')
Future<List<Events>> findAllEvents();

@Query('SELECT * FROM events WHERE id = :id')
Expand All @@ -14,4 +14,29 @@ abstract class EventsDao {

@Query('DELETE FROM events WHERE id = :id')
Future<void> delete(int id);

@Query('UPDATE events SET startDate = :startDate, endDate= :endDate, startTime = :startTime, endTime = :endTime,location = :location, description = :description WHERE id = :id')
Future<void> updateNFTFromDetail(
String startDate,
String endDate,
String startTime,
String endTime,
String location,
String description,
int id,
);

@Query('UPDATE events SET listOfPerks = :listOfPerks WHERE id = :id')
Future<void> updateNFTFromPerks(
String listOfPerks,
int id,
);

@Query('UPDATE events SET numberOfTickets = :numberOfTickets, price = :price, isFreeDrops = :isFreeDrops WHERE id = :id')
Future<void> updateNFTFromPrice(
int id,
String numberOfTickets,
String price,
String isFreeDrops,
);
}
Loading

0 comments on commit 059a90d

Please sign in to comment.