56 lines
1.3 KiB
Dart
56 lines
1.3 KiB
Dart
import 'package:hl_lieferservice/model/delivery.dart';
|
|
import 'package:json_annotation/json_annotation.dart';
|
|
|
|
part 'delivery_update.g.dart';
|
|
|
|
@JsonSerializable(fieldRename: FieldRename.snake)
|
|
class DeliveryUpdateDTO {
|
|
DeliveryUpdateDTO({
|
|
required this.deliveryId,
|
|
this.note,
|
|
this.finishedDate,
|
|
this.discount,
|
|
this.selectedPaymentMethodId,
|
|
this.state,
|
|
this.carId,
|
|
});
|
|
|
|
String deliveryId;
|
|
String? note;
|
|
String? finishedDate;
|
|
String? state;
|
|
int? carId;
|
|
String? selectedPaymentMethodId;
|
|
double? discount;
|
|
|
|
factory DeliveryUpdateDTO.fromJson(Map<String, dynamic> json) =>
|
|
_$DeliveryUpdateDTOFromJson(json);
|
|
|
|
factory DeliveryUpdateDTO.fromEntity(Delivery delivery) {
|
|
String state = "";
|
|
|
|
switch (delivery.state) {
|
|
case DeliveryState.finished:
|
|
state = "geliefert";
|
|
break;
|
|
case DeliveryState.ongoing:
|
|
state = "laufend";
|
|
break;
|
|
case DeliveryState.onhold:
|
|
state = "vertagt";
|
|
break;
|
|
case DeliveryState.canceled:
|
|
state = "abgebrochen";
|
|
break;
|
|
}
|
|
|
|
return DeliveryUpdateDTO(
|
|
deliveryId: delivery.id,
|
|
state: state,
|
|
carId: delivery.carId,
|
|
);
|
|
}
|
|
|
|
Map<dynamic, dynamic> toJson() => _$DeliveryUpdateDTOToJson(this);
|
|
}
|