Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
history_repository_impl.dart
Go to the documentation of this file.
1
2import 'package:dartz/dartz.dart';
3import 'package:internet_connection_checker_plus/internet_connection_checker_plus.dart';
4
5import '../../../../core/error/exceptipns/server_exception.dart';
6import '../../../../core/error/failures.dart';
7import '../../../../core/ui/theme/color_palette.dart';
8import '../../../../core/common/entities/collection_entity.dart';
9import '../../domain/repositories/history_repository.dart';
10import '../datasources/history_local_datasource.dart';
11import '../datasources/history_remote_datasource.dart';
12
16
18 required this.remoteDataSource,
19 required this.localDataSource,
20 });
21
22 @override
23 Future<Either<Failure, List<CollectionEntity>>> getPendingCollections({
24 required int userId
25 }) async {
26 try {
27 List<CollectionEntity> result;
28 bool hasInternetConnection = await InternetConnection().hasInternetAccess;
29 if (hasInternetConnection) {
30 result = await remoteDataSource.getPendingCollections(userId: userId);
31 } else {
32 result = await localDataSource.getPendingCollections();
33 }
34 return right(result);
35 } on ServerException catch (e) {
36 return left(ServerFailure(message: e.message, color: ColorPalette.red));
37 } catch (e) {
38 return left(ServerFailure(message: e.toString(), color: ColorPalette.red));
39 }
40 }
41
42 @override
43 Future<Either<Failure, List<CollectionEntity>>> getHistoryCollections({
44 required int userId,
45 required String? period,
46 DateTime? dateStart,
47 DateTime? dateEnd,
48 }) async {
49 try {
50 List<CollectionEntity> result;
51 bool hasInternetConnection = await InternetConnection().hasInternetAccess;
52 if (hasInternetConnection){
53 result = await remoteDataSource.getHistoryCollections(
56 dateStart: dateStart,
57 dateEnd: dateEnd,
58 );
59 } else {
60 if (period == 'week') {
61 result = await localDataSource.getThisWeekHistoryCollections();
62 } else {
63 result = await localDataSource.getThisMonthHistoryCollections();
64 }
65 }
66 return right(result);
67 } on ServerException catch (e) {
68 return left(ServerFailure(message: e.message, color: ColorPalette.red));
69 } catch (e) {
70 return left(ServerFailure(message: e.toString(), color: ColorPalette.red));
71 }
72 }
73
74}
sealed class CheckInOutEvent extends Equatable userId
Future< List< CollectionModel > > getPendingCollections() async
Future< List< CollectionModel > > getThisMonthHistoryCollections() async
Future< List< CollectionModel > > getThisWeekHistoryCollections() async
Future< List< CollectionModel > > getHistoryCollections({ required int userId, String? period, DateTime? dateStart, DateTime? dateEnd, }) async
Future< List< CollectionModel > > getPendingCollections({required int userId}) async
final HistoryLocalDatasource localDataSource
override Future< Either< Failure, List< CollectionEntity > > > getPendingCollections({ required int userId }) async
final HistoryRemoteDatasource remoteDataSource
HistoryRepositoryImpl({ required this.remoteDataSource, required this.localDataSource, })
override Future< Either< Failure, List< CollectionEntity > > > getHistoryCollections({ required int userId, required String? period, DateTime? dateStart, DateTime? dateEnd, }) async
class Partner String
final Color color
Definition failures.dart:1
abstract class Failure extends Equatable ServerFailure({ required super.message, required super.color, })
final String message
Definition failures.dart:0
abstract class PeriodEvent extends Equatable period