Skip to content

Commit

Permalink
feat: floor database for events storage
Browse files Browse the repository at this point in the history
  • Loading branch information
AhsanRns committed May 16, 2024
1 parent d398452 commit 32044b5
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 24 deletions.
38 changes: 22 additions & 16 deletions evently/lib/models/events.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
import 'package:equatable/equatable.dart';
import 'package:floor/floor.dart';
import 'package:pylons_sdk/low_level.dart';
import 'package:fixnum/fixnum.dart';

enum FreeDrop { yes, no, unselected }

@entity
class Events extends Equatable {
@primaryKey
final int? id;

final String eventName;
final String hostName;
final String thumbnail;
final String startDate;
final String endDate;
final String startTime;
final String endTime;
final String location;
final String description;
final String numberOfTickets;
final String price;
final String listOfPerks;
final String isFreeDrops;
final String cookbookID;
final String recipeID;

const Events({
///* overview data
this.eventName = '',
Expand All @@ -30,24 +51,9 @@ class Events extends Equatable {
///* other
this.cookbookID = '',
this.recipeID = '',
this.id,
});

final String eventName;
final String hostName;
final String thumbnail;
final String startDate;
final String endDate;
final String startTime;
final String endTime;
final String location;
final String description;
final String numberOfTickets;
final String price;
final String listOfPerks;
final String isFreeDrops;
final String cookbookID;
final String recipeID;

factory Events.fromRecipe(Recipe recipe) {
Map<String, String> map = _extractAttributeValues(recipe.entries.itemOutputs[0].strings);
return Events(
Expand Down
3 changes: 1 addition & 2 deletions evently/lib/repository/repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ class RepositoryImp implements Repository {
final response = await localDataSource.getEvents();

return Right(response);
} on Exception catch (exception) {
crashlyticsHelper.recordFatalError(error: exception.toString());
} on Exception catch (_) {
return Left(CacheFailure(LocaleKeys.something_wrong.tr()));
}
}
Expand Down
9 changes: 5 additions & 4 deletions evently/lib/screens/event_hub/event_hub_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:evently/generated/locale_keys.g.dart';
import 'package:evently/models/events.dart';
import 'package:evently/repository/repository.dart';
import 'package:evently/utils/extension_util.dart';
import 'package:evently/widgets/loading_with_progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:injectable/injectable.dart';
import 'package:pylons_sdk/pylons_sdk.dart';
Expand Down Expand Up @@ -94,17 +95,17 @@ class EventHubViewModel extends ChangeNotifier {
}

Future<void> getDraftsList() async {
// final loading = Loading()..showLoading(message: LocaleKeys.loading.tr());
final loading = LoadingProgress()..showLoadingWithProgress(message: LocaleKeys.loading.tr());

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

if (getNftResponse.isLeft()) {
if (getEventResponse.isLeft()) {
loading.dismiss();
LocaleKeys.something_wrong.tr().show();
return;
}

nftDraftList = getNftResponse.getOrElse(() => []);
// nftDraftList = getNftResponse.getOrElse(() => []);

loading.dismiss();

Expand Down
12 changes: 12 additions & 0 deletions evently/lib/services/third_party_services/database.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'dart:async';
import 'package:evently/models/events.dart';
import 'package:evently/services/third_party_services/event_dao.dart';
import 'package:floor/floor.dart';
import 'package:sqflite/sqflite.dart' as sqflite;

part 'database.g.dart';

@Database(version: 6, entities: [Events])
abstract class AppDatabase extends FloorDatabase {
EventsDao get eventsDao;
}
205 changes: 205 additions & 0 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.

17 changes: 17 additions & 0 deletions evently/lib/services/third_party_services/event_dao.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:evently/models/events.dart';
import 'package:floor/floor.dart';

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

@Query('SELECT * FROM events WHERE id = :id')
Future<Events?> findEventsById(int id);

@insert
Future<int> insertEvents(Events events);

@Query('DELETE FROM events WHERE id = :id')
Future<void> delete(int id);
}
2 changes: 2 additions & 0 deletions evently/lib/utils/di/di.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// coverage: false
// coverage:ignore-file

import 'package:evently/services/third_party_services/database.dart';
import 'package:evently/utils/di/di.config.dart';
import 'package:get_it/get_it.dart';
import 'package:injectable/injectable.dart';
Expand All @@ -13,5 +14,6 @@ final sl = GetIt.I;
@InjectableInit()
void configureDependencies() {
sl.registerSingletonAsync<SharedPreferences>(() => SharedPreferences.getInstance());
sl.registerSingletonAsync<AppDatabase>(() => $FloorAppDatabase.databaseBuilder('app_database.db').build());
sl.init();
}
Loading

0 comments on commit 32044b5

Please sign in to comment.