add cartonsize api
This commit is contained in:
@@ -5,6 +5,8 @@ const user_collection = "users";
|
|||||||
const invitations_collection = "invitations";
|
const invitations_collection = "invitations";
|
||||||
const privilege_collection = "privileges";
|
const privilege_collection = "privileges";
|
||||||
const markets_collection = "markets";
|
const markets_collection = "markets";
|
||||||
|
const carton_sizes_collection = "carton_sizes";
|
||||||
|
|
||||||
const packages_collection = "packages";
|
const packages_collection = "packages";
|
||||||
const messages_collection = "messages";
|
const messages_collection = "messages";
|
||||||
const fcs_shipment_collection = "fcs_shipments";
|
const fcs_shipment_collection = "fcs_shipments";
|
||||||
|
|||||||
@@ -5,4 +5,26 @@ class CartonSize {
|
|||||||
double width;
|
double width;
|
||||||
double height;
|
double height;
|
||||||
CartonSize({this.id, this.name, this.length, this.width, this.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 'dart:async';
|
||||||
|
|
||||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
|
import 'package:fcs/domain/constants.dart';
|
||||||
import 'package:fcs/domain/entities/carton_size.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:fcs/pages/main/model/base_model.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
|
|
||||||
@@ -20,26 +22,49 @@ class CartonSizeModel extends BaseModel {
|
|||||||
|
|
||||||
void initUser(user) {
|
void initUser(user) {
|
||||||
super.initUser(user);
|
super.initUser(user);
|
||||||
cartonSizes = [
|
_loadCartonSizes();
|
||||||
CartonSize(
|
}
|
||||||
id: "1", name: "FCS Small Box", length: 16, width: 12, height: 12),
|
|
||||||
CartonSize(
|
Future<void> _loadCartonSizes() async {
|
||||||
id: "2", name: "FCS Medium Box", length: 22, width: 16, height: 15),
|
try {
|
||||||
CartonSize(
|
if (listener != null) listener.cancel();
|
||||||
id: "3", name: "FCS Large Box", length: 28, width: 15, height: 16)
|
|
||||||
];
|
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
|
@override
|
||||||
logout() async {
|
logout() async {
|
||||||
if (listener != null) await listener.cancel();
|
if (listener != null) await listener.cancel();
|
||||||
|
|
||||||
cartonSizes = [];
|
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