Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
unloading_repository_impl.dart
Go to the documentation of this file.
1import 'package:dartz/dartz.dart';
2import 'package:geolocator/geolocator.dart';
3
4import '../../../../core/api/api_client.dart';
5import '../../../../core/api/api_endpoints.dart';
6import '../../../../core/error/exceptipns/server_exception.dart';
7import '../../../../core/error/failures.dart';
8import '../../../../core/services/offline_sync_service.dart';
9import '../../../../core/services/service_locator.dart';
10import '../../../../core/ui/theme/color_palette.dart';
11import '../../domain/entities/unloading_collection_entity.dart';
12import '../../domain/entities/unloading_history_entity.dart';
13import '../../domain/entities/warehouse_responsible_entity.dart';
14import '../../domain/repositories/unloading_repository.dart';
15import '../datasources/unloading_remote_datasource.dart';
16import '../models/unloading_request_model.dart';
17
19
22
23 UnloadingRepositoryImpl({required this.remoteDataSource});
24
25 @override
26 Future<Either<Failure, List<UnloadingCollectionEntity>>> getPendingUnloadingCollections(int userId) async {
27 try{
28 final OfflineSyncService offlineSyncService = OfflineSyncService();
29 await offlineSyncService.syncPendingOperations();
30 final collections = await remoteDataSource.getPendingUnloadingCollections(userId: userId);
31 return right(collections);
32 } on ServerException catch (e) {
33 return left(ServerFailure(message: e.message, color: ColorPalette.red));
34 } catch (e) {
35 return left(ServerFailure(message: e.toString(), color: ColorPalette.red));
36 }
37 }
38
39 @override
40 Future<Either<Failure, List<UnloadingHistoryEntity>>> getHistoryUnloading(int userId) async {
41 try {
42 final history = await remoteDataSource.getHistoryUnloading(userId: userId);
43 return right(history);
44 } on ServerException catch (e) {
45 return left(ServerFailure(message: e.message, color: ColorPalette.red));
46 } catch (e) {
47 return left(ServerFailure(message: e.toString(), color: ColorPalette.red));
48 }
49 }
50
51 @override
52 Future<Either<Failure, List<WarehouseResponsibleEntity>>> getWarehouseResponsibleList(int userId) async {
53 try {
54 final warehouseResponsibles = await remoteDataSource.getWarehouseResponsibleList(userId: userId);
55 return right(warehouseResponsibles);
56 } on ServerException catch (e) {
57 return left(ServerFailure(message: e.message, color: ColorPalette.red));
58 } catch (e) {
59 return left(ServerFailure(message: e.toString(), color: ColorPalette.red));
60 }
61 }
62
63 Future<bool> _sendLocationToServer({
64 required int driverId,
65 required double latitude,
66 required double longitude,
67 int? poId,
68 String? poStatus,
69 }) async {
70 try {
71 final data = {
72 "driverId": driverId,
73 "lag": latitude.toString(),
74 "longitude": longitude.toString(),
75 "poId": poId,
76 "poStatus": poStatus,
77 };
78
79 final response = await _apiClient.post(
80 url: ApiEndpoints.sendGeoLocation,
81 data: data,
82 );
83
84 return response.isNotEmpty;
85 } catch (e) {
86 return false;
87 }
88 }
89
90 @override
91 Future<Either<Failure, bool>> sendUnloading(UnloadingRequestModel unloadingRequestModel) async {
92 try {
93 Position position = await Geolocator.getCurrentPosition(
94 locationSettings: const LocationSettings(
95 accuracy: LocationAccuracy.high,
96 ),
97 );
98
100 driverId: unloadingRequestModel.userId,
101 latitude: position.latitude,
102 longitude: position.longitude,
103 poStatus: "end",
104 );
105
106 await remoteDataSource.sendUnloading(unloadingRequestModel: unloadingRequestModel);
107 return right(true);
108 } on ServerException catch (e) {
109 return left(ServerFailure(message: e.message, color: ColorPalette.red));
110 } catch (e) {
111 return left(ServerFailure(message: e.toString(), color: ColorPalette.red));
112 }
113 }
114}
sealed class CheckInOutEvent extends Equatable userId
Future< Map< String, dynamic > > post({ String? url, String? path, required Map< String, dynamic > data, }) async
static const red
Future< void > syncPendingOperations() async
override Future< Either< Failure, bool > > sendUnloading(UnloadingRequestModel unloadingRequestModel) async
final UnloadingRemoteDatasource remoteDataSource
override Future< Either< Failure, List< UnloadingCollectionEntity > > > getPendingUnloadingCollections(int userId) async
UnloadingRepositoryImpl({required this.remoteDataSource})
Future< bool > _sendLocationToServer({ required int driverId, required double latitude, required double longitude, int? poId, String? poStatus, }) async
override Future< Either< Failure, List< WarehouseResponsibleEntity > > > getWarehouseResponsibleList(int userId) async
override Future< Either< Failure, List< UnloadingHistoryEntity > > > getHistoryUnloading(int userId) async
sealed class CollectionsState extends Equatable collections
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
final sl
final ApiClient _apiClient
class PendingUnloadingCollectionsLoaded extends UnloadingState history