add fcs shipment service

This commit is contained in:
Sai Naw Wun
2020-10-07 17:22:01 +06:30
parent 897e5c9b93
commit a0569a0986
5 changed files with 88 additions and 1 deletions

View File

@@ -0,0 +1,23 @@
import 'package:fcs/domain/entities/fcs_shipment.dart';
import 'package:fcs/helpers/api_helper.dart';
import 'package:fcs/helpers/firebase_helper.dart';
import 'package:logging/logging.dart';
class FcsShipmentDataProvider {
final log = Logger('FcsShipmentDataProvider');
Future<void> createFcsShipment(FcsShipment fcsShipment) async {
return await requestAPI("/fcs_shipments", "POST",
payload: fcsShipment.toMap(), token: await getToken());
}
Future<void> updateFcsShipment(FcsShipment fcsShipment) async {
return await requestAPI("/fcs_shipments", "PUT",
payload: fcsShipment.toMap(), token: await getToken());
}
Future<void> deleteFcsShipment(FcsShipment fcsShipment) async {
return await requestAPI("/fcs_shipments", "DELETE",
payload: fcsShipment.toMap(), token: await getToken());
}
}

View File

@@ -0,0 +1,31 @@
import 'package:fcs/data/provider/fcs_shipment_data_provider.dart';
import 'package:fcs/domain/entities/connectivity.dart';
import 'package:fcs/domain/entities/fcs_shipment.dart';
import 'package:flutter/material.dart';
import 'fcs_shipment_service.dart';
class FcsShipmentServiceImp implements FcsShipmentService {
FcsShipmentServiceImp({
@required this.connectivity,
@required this.shipmentDataProvider,
});
final Connectivity connectivity;
final FcsShipmentDataProvider shipmentDataProvider;
@override
Future<void> createFcsShipment(FcsShipment fcsShipment) {
return shipmentDataProvider.createFcsShipment(fcsShipment);
}
@override
Future<void> updateFcsShipment(FcsShipment fcsShipment) {
return shipmentDataProvider.updateFcsShipment(fcsShipment);
}
@override
Future<void> deleteFcsShipment(FcsShipment fcsShipment) {
return shipmentDataProvider.deleteFcsShipment(fcsShipment);
}
}

View File

@@ -0,0 +1,7 @@
import 'package:fcs/domain/entities/fcs_shipment.dart';
abstract class FcsShipmentService {
Future<void> createFcsShipment(FcsShipment fcsShipment);
Future<void> updateFcsShipment(FcsShipment fcsShipment);
Future<void> deleteFcsShipment(FcsShipment fcsShipment);
}

View File

@@ -1,7 +1,10 @@
import 'package:fcs/data/provider/auth_fb.dart'; import 'package:fcs/data/provider/auth_fb.dart';
import 'package:fcs/data/provider/common_data_provider.dart'; import 'package:fcs/data/provider/common_data_provider.dart';
import 'package:fcs/data/provider/fcs_shipment_data_provider.dart';
import 'package:fcs/data/provider/package_data_provider.dart'; import 'package:fcs/data/provider/package_data_provider.dart';
import 'package:fcs/data/provider/user_data_provider.dart'; import 'package:fcs/data/provider/user_data_provider.dart';
import 'package:fcs/data/services/fcs_shipment_imp.dart';
import 'package:fcs/data/services/fcs_shipment_service.dart';
import 'auth_imp.dart'; import 'auth_imp.dart';
import 'auth_service.dart'; import 'auth_service.dart';
@@ -22,6 +25,7 @@ class Services {
PackageService _packageService; PackageService _packageService;
MessagingService _messagingService; MessagingService _messagingService;
CommonService _commonService; CommonService _commonService;
FcsShipmentService _fcsShipmentService;
Services._() { Services._() {
_authService = AuthServiceImp( _authService = AuthServiceImp(
authFb: AuthFb.instance, authFb: AuthFb.instance,
@@ -33,6 +37,8 @@ class Services {
_packageService = PackageServiceImp( _packageService = PackageServiceImp(
connectivity: null, packageDataProvider: PackageDataProvider()); connectivity: null, packageDataProvider: PackageDataProvider());
_commonService = CommonServiceImp(commonDataProvider: CommonDataProvider()); _commonService = CommonServiceImp(commonDataProvider: CommonDataProvider());
_fcsShipmentService = FcsShipmentServiceImp(
connectivity: null, shipmentDataProvider: FcsShipmentDataProvider());
} }
AuthService get authService => _authService; AuthService get authService => _authService;
@@ -40,4 +46,5 @@ class Services {
MessagingService get messagingService => _messagingService; MessagingService get messagingService => _messagingService;
PackageService get packageService => _packageService; PackageService get packageService => _packageService;
CommonService get commonService => _commonService; CommonService get commonService => _commonService;
FcsShipmentService get fcsShipmentService => _fcsShipmentService;
} }

View File

@@ -1,4 +1,5 @@
class FcsShipment { class FcsShipment {
String id;
DateTime shipDate; DateTime shipDate;
String shipmentNumber; String shipmentNumber;
DateTime cutoffDate; DateTime cutoffDate;
@@ -11,7 +12,8 @@ class FcsShipment {
String status; String status;
String remark; String remark;
FcsShipment( FcsShipment(
{this.shipDate, {this.id,
this.shipDate,
this.shipmentNumber, this.shipmentNumber,
this.cutoffDate, this.cutoffDate,
this.shipType, this.shipType,
@@ -22,4 +24,21 @@ class FcsShipment {
this.port, this.port,
this.destination, this.destination,
this.remark}); this.remark});
Map<String, dynamic> toMap() {
return {
"id": id,
'shipment_date': shipDate?.toUtc()?.toIso8601String(),
'shipment_number': shipmentNumber,
'cutoff_date': cutoffDate?.toUtc()?.toIso8601String(),
'shipment_type': shipType,
'arrival_date': arrivalDate?.toUtc()?.toIso8601String(),
'departure_date': departureDate?.toUtc()?.toIso8601String(),
'consignee': consignee,
'port': port,
'destination': destination,
'status': status,
'remark': remark,
};
}
} }