course-work/lib/models/order.dart

65 lines
1.8 KiB
Dart
Raw Normal View History

2022-12-27 05:13:07 +00:00
import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:selfprivacy/models/item.dart';
2022-12-27 05:13:07 +00:00
part 'order.g.dart';
@JsonSerializable()
class Order {
2022-12-27 05:13:07 +00:00
factory Order.fromJson(final Map<String, dynamic> json) =>
_$OrderFromJson(json);
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')
final String customerName;
2022-12-27 05:13:07 +00:00
@JsonKey(name: 'customer_phone')
final String customerPhone;
2022-12-27 05:13:07 +00:00
@JsonKey(name: 'order_date')
final String orderDate;
2022-12-27 05:13:07 +00:00
@JsonKey(name: 'delivery_date')
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;
}
}