add cartonsize api
This commit is contained in:
@@ -5,6 +5,8 @@ const user_collection = "users";
|
||||
const invitations_collection = "invitations";
|
||||
const privilege_collection = "privileges";
|
||||
const markets_collection = "markets";
|
||||
const carton_sizes_collection = "carton_sizes";
|
||||
|
||||
const packages_collection = "packages";
|
||||
const messages_collection = "messages";
|
||||
const fcs_shipment_collection = "fcs_shipments";
|
||||
|
||||
@@ -5,4 +5,26 @@ class CartonSize {
|
||||
double width;
|
||||
double height;
|
||||
CartonSize({this.id, this.name, this.length, this.width, this.height});
|
||||
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'length': length,
|
||||
'width': width,
|
||||
'height': height,
|
||||
};
|
||||
}
|
||||
|
||||
factory CartonSize.fromMap(Map<String, dynamic> map, String id) {
|
||||
return CartonSize(
|
||||
id: id,
|
||||
name: map['name'],
|
||||
length: map['length'],
|
||||
width: map['width'],
|
||||
height: map['height'],
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/carton_size.dart';
|
||||
import 'package:fcs/helpers/firebase_helper.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
@@ -20,26 +22,49 @@ class CartonSizeModel extends BaseModel {
|
||||
|
||||
void initUser(user) {
|
||||
super.initUser(user);
|
||||
cartonSizes = [
|
||||
CartonSize(
|
||||
id: "1", name: "FCS Small Box", length: 16, width: 12, height: 12),
|
||||
CartonSize(
|
||||
id: "2", name: "FCS Medium Box", length: 22, width: 16, height: 15),
|
||||
CartonSize(
|
||||
id: "3", name: "FCS Large Box", length: 28, width: 15, height: 16)
|
||||
];
|
||||
_loadCartonSizes();
|
||||
}
|
||||
|
||||
Future<void> _loadCartonSizes() async {
|
||||
try {
|
||||
if (listener != null) listener.cancel();
|
||||
|
||||
listener = Firestore.instance
|
||||
.collection(
|
||||
"/$config_collection/$setting_doc_id/$carton_sizes_collection")
|
||||
.snapshots()
|
||||
.listen((QuerySnapshot snapshot) {
|
||||
cartonSizes.clear();
|
||||
cartonSizes = snapshot.documents.map((documentSnapshot) {
|
||||
var c = CartonSize.fromMap(
|
||||
documentSnapshot.data, documentSnapshot.documentID);
|
||||
return c;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
});
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
logout() async {
|
||||
if (listener != null) await listener.cancel();
|
||||
|
||||
cartonSizes = [];
|
||||
}
|
||||
|
||||
Future<void> addCartonSize(CartonSize cartonSize) async {}
|
||||
Future<void> addCartonSize(CartonSize cartonSize) async {
|
||||
await request("/carton_sizes", "POST",
|
||||
payload: cartonSize.toMap(), token: await getToken());
|
||||
}
|
||||
|
||||
Future<void> updateCartonSize(CartonSize cartonSize) async {}
|
||||
Future<void> updateCartonSize(CartonSize cartonSize) async {
|
||||
await request("/carton_sizes", "PUT",
|
||||
payload: cartonSize.toMap(), token: await getToken());
|
||||
}
|
||||
|
||||
Future<void> deleteCartonSize(String id) async {}
|
||||
Future<void> deleteCartonSize(String id) async {
|
||||
await request("/carton_sizes", "DELETE",
|
||||
payload: {"id": id}, token: await getToken());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user