2022-12-27 05:13:07 +00:00
|
|
|
import 'package:equatable/equatable.dart';
|
|
|
|
import 'package:json_annotation/json_annotation.dart';
|
2022-12-27 03:19:49 +00:00
|
|
|
import 'package:selfprivacy/models/item.dart';
|
|
|
|
|
2022-12-27 05:13:07 +00:00
|
|
|
part 'order.g.dart';
|
|
|
|
|
|
|
|
@JsonSerializable()
|
2022-12-27 03:19:49 +00:00
|
|
|
class Order {
|
2022-12-27 05:13:07 +00:00
|
|
|
factory Order.fromJson(final Map<String, dynamic> json) =>
|
|
|
|
_$OrderFromJson(json);
|
2022-12-27 03:19:49 +00:00
|
|
|
Order({
|
|
|
|
required this.title,
|
|
|
|
required this.description,
|
|
|
|
required this.id,
|
|
|
|
required this.customerName,
|
|
|
|
required this.customerPhone,
|
|
|
|
required this.orderDate,
|
|
|
|
required this.deliveryDate,
|
|
|
|
required this.address,
|
|
|
|
required this.status,
|
|
|
|
required this.courierId,
|
|
|
|
required this.items,
|
|
|
|
});
|
|
|
|
|
|
|
|
final String title;
|
|
|
|
final String description;
|
2022-12-27 05:13:07 +00:00
|
|
|
@JsonKey(name: 'customer_name')
|
2022-12-27 03:19:49 +00:00
|
|
|
final String customerName;
|
2022-12-27 05:13:07 +00:00
|
|
|
@JsonKey(name: 'customer_phone')
|
2022-12-27 03:19:49 +00:00
|
|
|
final String customerPhone;
|
2022-12-27 05:13:07 +00:00
|
|
|
@JsonKey(name: 'order_date')
|
2022-12-27 03:19:49 +00:00
|
|
|
final String orderDate;
|
2022-12-27 05:13:07 +00:00
|
|
|
@JsonKey(name: 'delivery_date')
|
2022-12-27 03:19:49 +00:00
|
|
|
final String deliveryDate;
|
|
|
|
final String address;
|
|
|
|
final String status;
|
|
|
|
final int id;
|
|
|
|
final int courierId;
|
|
|
|
|
|
|
|
final List<Item> items;
|
2022-12-27 05:13:07 +00:00
|
|
|
|
|
|
|
// tojson
|
|
|
|
Map<String, dynamic> toJson() => _$OrderToJson(this);
|
|
|
|
Map<String, dynamic> toJsonAsNew() {
|
|
|
|
final Map<String, dynamic> data = _$OrderToJson(this);
|
|
|
|
// To "order_in" goes everything except items
|
|
|
|
data['order_in'] = {
|
|
|
|
'title': data['title'],
|
|
|
|
'description': data['description'],
|
|
|
|
'customer_name': data['customer_name'],
|
|
|
|
'customer_phone': data['customer_phone'],
|
|
|
|
'order_date': data['order_date'],
|
|
|
|
'delivery_date': data['delivery_date'],
|
|
|
|
'address': data['address'],
|
|
|
|
'status': data['status'],
|
|
|
|
'courier_id': data['courier_id'],
|
|
|
|
};
|
|
|
|
// To "order_items" goes only items
|
|
|
|
data['order_items'] = data['items'];
|
|
|
|
// Remove items from data
|
|
|
|
data.remove('items');
|
|
|
|
return data;
|
|
|
|
}
|
2022-12-27 03:19:49 +00:00
|
|
|
}
|