feat: save order
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import 'dart:convert';
|
||||
|
||||
class OrderRequestModel {
|
||||
final String? outletId;
|
||||
final String? userId;
|
||||
final String? tableNumber;
|
||||
final String? orderType;
|
||||
final String? notes;
|
||||
final List<OrderItemRequest>? orderItems;
|
||||
final String? customerName;
|
||||
|
||||
OrderRequestModel({
|
||||
this.outletId,
|
||||
this.userId,
|
||||
this.tableNumber,
|
||||
this.orderType,
|
||||
this.notes,
|
||||
this.orderItems,
|
||||
this.customerName,
|
||||
});
|
||||
|
||||
factory OrderRequestModel.fromJson(String str) =>
|
||||
OrderRequestModel.fromMap(json.decode(str));
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory OrderRequestModel.fromMap(Map<String, dynamic> json) =>
|
||||
OrderRequestModel(
|
||||
outletId: json["outlet_id"],
|
||||
userId: json["user_id"],
|
||||
tableNumber: json["table_number"],
|
||||
orderType: json["order_type"],
|
||||
notes: json["notes"],
|
||||
orderItems: json["order_items"] == null
|
||||
? []
|
||||
: List<OrderItemRequest>.from(
|
||||
json["order_items"].map((x) => OrderItemRequest.fromMap(x))),
|
||||
customerName: json["customer_name"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toMap() => {
|
||||
"outlet_id": outletId,
|
||||
"user_id": userId,
|
||||
"table_number": tableNumber,
|
||||
"order_type": orderType,
|
||||
"notes": notes,
|
||||
"order_items": orderItems == null
|
||||
? []
|
||||
: List<dynamic>.from(orderItems!.map((x) => x.toMap())),
|
||||
"customer_name": customerName,
|
||||
};
|
||||
}
|
||||
|
||||
class OrderItemRequest {
|
||||
final String? productId;
|
||||
final int? quantity;
|
||||
final int? unitPrice;
|
||||
final String? notes;
|
||||
|
||||
OrderItemRequest({
|
||||
this.productId,
|
||||
this.quantity,
|
||||
this.unitPrice,
|
||||
this.notes,
|
||||
});
|
||||
|
||||
factory OrderItemRequest.fromJson(String str) =>
|
||||
OrderItemRequest.fromMap(json.decode(str));
|
||||
|
||||
factory OrderItemRequest.fromMap(Map<String, dynamic> json) =>
|
||||
OrderItemRequest(
|
||||
productId: json["product_id"],
|
||||
quantity: json["quantity"],
|
||||
unitPrice: json["unit_price"]?.toDouble(),
|
||||
notes: json["notes"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toMap() => {
|
||||
"product_id": productId,
|
||||
"quantity": quantity,
|
||||
"unit_price": unitPrice,
|
||||
"notes": notes,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user