split bill
This commit is contained in:
@@ -236,4 +236,29 @@ class OrderRemoteDataProvider {
|
||||
return DC.error(OrderFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
|
||||
Future<DC<OrderFailure, PaymentDto>> createSplitBill(
|
||||
PaymentSplitBillRequestDto request,
|
||||
) async {
|
||||
try {
|
||||
final response = await _apiClient.post(
|
||||
"${ApiPath.orders}/split-bill",
|
||||
data: request.toRequest(),
|
||||
headers: getAuthorizationHeader(),
|
||||
);
|
||||
|
||||
if (response.data['success'] == false) {
|
||||
return DC.error(OrderFailure.unexpectedError());
|
||||
}
|
||||
|
||||
final payment = PaymentDto.fromJson(
|
||||
response.data['data'] as Map<String, dynamic>,
|
||||
);
|
||||
|
||||
return DC.data(payment);
|
||||
} on ApiFailure catch (e, s) {
|
||||
log('createSplitBillError', name: _logName, error: e, stackTrace: s);
|
||||
return DC.error(OrderFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,3 +69,102 @@ class PaymentItemRequestDto with _$PaymentItemRequestDto {
|
||||
amount: request.amount,
|
||||
);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class PaymentSplitBillRequestDto with _$PaymentSplitBillRequestDto {
|
||||
const PaymentSplitBillRequestDto._();
|
||||
|
||||
const factory PaymentSplitBillRequestDto({
|
||||
@JsonKey(name: "order_id") String? orderId,
|
||||
@JsonKey(name: "payment_method_id") String? paymentMethodId,
|
||||
@JsonKey(name: "customer_id") String? customerId,
|
||||
@JsonKey(name: "customer_name") String? customerName,
|
||||
@JsonKey(name: "type") String? type, // e.g., "AMOUNT" or "ITEM"
|
||||
@JsonKey(name: "amount") int? amount,
|
||||
@JsonKey(name: "items") List<PaymentItemSplitBillRequestDto>? items,
|
||||
}) = _PaymentSplitBillRequestDto;
|
||||
|
||||
factory PaymentSplitBillRequestDto.fromJson(Map<String, dynamic> json) =>
|
||||
_$PaymentSplitBillRequestDtoFromJson(json);
|
||||
|
||||
// Optional mapper ke domain
|
||||
PaymentSplitBillRequest toDomain() => PaymentSplitBillRequest(
|
||||
orderId: orderId ?? '',
|
||||
paymentMethodId: paymentMethodId ?? '',
|
||||
customerId: customerId ?? '',
|
||||
type: type?.toSplitType() ?? SplitType.unknown,
|
||||
amount: amount ?? 0,
|
||||
items: items?.map((e) => e.toDomain()).toList() ?? [],
|
||||
customerName: customerName ?? '',
|
||||
);
|
||||
|
||||
factory PaymentSplitBillRequestDto.fromDomain(
|
||||
PaymentSplitBillRequest request,
|
||||
) => PaymentSplitBillRequestDto(
|
||||
orderId: request.orderId,
|
||||
paymentMethodId: request.paymentMethodId,
|
||||
customerId: request.customerId,
|
||||
type: request.type.toStringType(),
|
||||
amount: request.amount,
|
||||
items: request.items
|
||||
.map((e) => PaymentItemSplitBillRequestDto.fromDomain(e))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toRequest() {
|
||||
Map<String, dynamic> data = {
|
||||
'order_id': orderId,
|
||||
'payment_method_id': paymentMethodId,
|
||||
'type': type,
|
||||
};
|
||||
|
||||
if (customerId != null && customerId != '') {
|
||||
data['customer_id'] = customerId;
|
||||
}
|
||||
|
||||
if (customerName != null && customerName != '') {
|
||||
data['customer_name'] = customerName;
|
||||
}
|
||||
|
||||
if (type == 'AMOUNT') {
|
||||
data['amount'] = amount;
|
||||
}
|
||||
|
||||
if (type == 'ITEM') {
|
||||
data['items'] = items?.map((item) => item.toRequest()).toList();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@freezed
|
||||
class PaymentItemSplitBillRequestDto with _$PaymentItemSplitBillRequestDto {
|
||||
const PaymentItemSplitBillRequestDto._();
|
||||
|
||||
const factory PaymentItemSplitBillRequestDto({
|
||||
@JsonKey(name: "order_item_id") String? orderItemId,
|
||||
@JsonKey(name: "quantity") int? quantity,
|
||||
}) = _PaymentItemSplitBillRequestDto;
|
||||
|
||||
factory PaymentItemSplitBillRequestDto.fromJson(Map<String, dynamic> json) =>
|
||||
_$PaymentItemSplitBillRequestDtoFromJson(json);
|
||||
|
||||
// Optional mapper ke domain
|
||||
PaymentItemSplitBillRequest toDomain() => PaymentItemSplitBillRequest(
|
||||
orderItemId: orderItemId ?? '',
|
||||
quantity: quantity ?? 0,
|
||||
);
|
||||
|
||||
factory PaymentItemSplitBillRequestDto.fromDomain(
|
||||
PaymentItemSplitBillRequest request,
|
||||
) => PaymentItemSplitBillRequestDto(
|
||||
orderItemId: request.orderItemId,
|
||||
quantity: request.quantity,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toRequest() => {
|
||||
'order_item_id': orderItemId,
|
||||
'quantity': quantity,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import '../../common/extension/extension.dart';
|
||||
import '../../common/types/split_type.dart';
|
||||
import '../../domain/order/order.dart';
|
||||
|
||||
part 'order_dtos.freezed.dart';
|
||||
|
||||
@@ -2851,6 +2851,559 @@ abstract class _PaymentItemRequestDto extends PaymentItemRequestDto {
|
||||
get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
PaymentSplitBillRequestDto _$PaymentSplitBillRequestDtoFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) {
|
||||
return _PaymentSplitBillRequestDto.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$PaymentSplitBillRequestDto {
|
||||
@JsonKey(name: "order_id")
|
||||
String? get orderId => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "payment_method_id")
|
||||
String? get paymentMethodId => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "customer_id")
|
||||
String? get customerId => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "customer_name")
|
||||
String? get customerName => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "type")
|
||||
String? get type => throw _privateConstructorUsedError; // e.g., "AMOUNT" or "ITEM"
|
||||
@JsonKey(name: "amount")
|
||||
int? get amount => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "items")
|
||||
List<PaymentItemSplitBillRequestDto>? get items =>
|
||||
throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this PaymentSplitBillRequestDto to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of PaymentSplitBillRequestDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$PaymentSplitBillRequestDtoCopyWith<PaymentSplitBillRequestDto>
|
||||
get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $PaymentSplitBillRequestDtoCopyWith<$Res> {
|
||||
factory $PaymentSplitBillRequestDtoCopyWith(
|
||||
PaymentSplitBillRequestDto value,
|
||||
$Res Function(PaymentSplitBillRequestDto) then,
|
||||
) =
|
||||
_$PaymentSplitBillRequestDtoCopyWithImpl<
|
||||
$Res,
|
||||
PaymentSplitBillRequestDto
|
||||
>;
|
||||
@useResult
|
||||
$Res call({
|
||||
@JsonKey(name: "order_id") String? orderId,
|
||||
@JsonKey(name: "payment_method_id") String? paymentMethodId,
|
||||
@JsonKey(name: "customer_id") String? customerId,
|
||||
@JsonKey(name: "customer_name") String? customerName,
|
||||
@JsonKey(name: "type") String? type,
|
||||
@JsonKey(name: "amount") int? amount,
|
||||
@JsonKey(name: "items") List<PaymentItemSplitBillRequestDto>? items,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$PaymentSplitBillRequestDtoCopyWithImpl<
|
||||
$Res,
|
||||
$Val extends PaymentSplitBillRequestDto
|
||||
>
|
||||
implements $PaymentSplitBillRequestDtoCopyWith<$Res> {
|
||||
_$PaymentSplitBillRequestDtoCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of PaymentSplitBillRequestDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? orderId = freezed,
|
||||
Object? paymentMethodId = freezed,
|
||||
Object? customerId = freezed,
|
||||
Object? customerName = freezed,
|
||||
Object? type = freezed,
|
||||
Object? amount = freezed,
|
||||
Object? items = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
orderId: freezed == orderId
|
||||
? _value.orderId
|
||||
: orderId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
paymentMethodId: freezed == paymentMethodId
|
||||
? _value.paymentMethodId
|
||||
: paymentMethodId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
customerId: freezed == customerId
|
||||
? _value.customerId
|
||||
: customerId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
customerName: freezed == customerName
|
||||
? _value.customerName
|
||||
: customerName // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
type: freezed == type
|
||||
? _value.type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
amount: freezed == amount
|
||||
? _value.amount
|
||||
: amount // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
items: freezed == items
|
||||
? _value.items
|
||||
: items // ignore: cast_nullable_to_non_nullable
|
||||
as List<PaymentItemSplitBillRequestDto>?,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$PaymentSplitBillRequestDtoImplCopyWith<$Res>
|
||||
implements $PaymentSplitBillRequestDtoCopyWith<$Res> {
|
||||
factory _$$PaymentSplitBillRequestDtoImplCopyWith(
|
||||
_$PaymentSplitBillRequestDtoImpl value,
|
||||
$Res Function(_$PaymentSplitBillRequestDtoImpl) then,
|
||||
) = __$$PaymentSplitBillRequestDtoImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({
|
||||
@JsonKey(name: "order_id") String? orderId,
|
||||
@JsonKey(name: "payment_method_id") String? paymentMethodId,
|
||||
@JsonKey(name: "customer_id") String? customerId,
|
||||
@JsonKey(name: "customer_name") String? customerName,
|
||||
@JsonKey(name: "type") String? type,
|
||||
@JsonKey(name: "amount") int? amount,
|
||||
@JsonKey(name: "items") List<PaymentItemSplitBillRequestDto>? items,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$PaymentSplitBillRequestDtoImplCopyWithImpl<$Res>
|
||||
extends
|
||||
_$PaymentSplitBillRequestDtoCopyWithImpl<
|
||||
$Res,
|
||||
_$PaymentSplitBillRequestDtoImpl
|
||||
>
|
||||
implements _$$PaymentSplitBillRequestDtoImplCopyWith<$Res> {
|
||||
__$$PaymentSplitBillRequestDtoImplCopyWithImpl(
|
||||
_$PaymentSplitBillRequestDtoImpl _value,
|
||||
$Res Function(_$PaymentSplitBillRequestDtoImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of PaymentSplitBillRequestDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? orderId = freezed,
|
||||
Object? paymentMethodId = freezed,
|
||||
Object? customerId = freezed,
|
||||
Object? customerName = freezed,
|
||||
Object? type = freezed,
|
||||
Object? amount = freezed,
|
||||
Object? items = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
_$PaymentSplitBillRequestDtoImpl(
|
||||
orderId: freezed == orderId
|
||||
? _value.orderId
|
||||
: orderId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
paymentMethodId: freezed == paymentMethodId
|
||||
? _value.paymentMethodId
|
||||
: paymentMethodId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
customerId: freezed == customerId
|
||||
? _value.customerId
|
||||
: customerId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
customerName: freezed == customerName
|
||||
? _value.customerName
|
||||
: customerName // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
type: freezed == type
|
||||
? _value.type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
amount: freezed == amount
|
||||
? _value.amount
|
||||
: amount // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
items: freezed == items
|
||||
? _value._items
|
||||
: items // ignore: cast_nullable_to_non_nullable
|
||||
as List<PaymentItemSplitBillRequestDto>?,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$PaymentSplitBillRequestDtoImpl extends _PaymentSplitBillRequestDto {
|
||||
const _$PaymentSplitBillRequestDtoImpl({
|
||||
@JsonKey(name: "order_id") this.orderId,
|
||||
@JsonKey(name: "payment_method_id") this.paymentMethodId,
|
||||
@JsonKey(name: "customer_id") this.customerId,
|
||||
@JsonKey(name: "customer_name") this.customerName,
|
||||
@JsonKey(name: "type") this.type,
|
||||
@JsonKey(name: "amount") this.amount,
|
||||
@JsonKey(name: "items") final List<PaymentItemSplitBillRequestDto>? items,
|
||||
}) : _items = items,
|
||||
super._();
|
||||
|
||||
factory _$PaymentSplitBillRequestDtoImpl.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _$$PaymentSplitBillRequestDtoImplFromJson(json);
|
||||
|
||||
@override
|
||||
@JsonKey(name: "order_id")
|
||||
final String? orderId;
|
||||
@override
|
||||
@JsonKey(name: "payment_method_id")
|
||||
final String? paymentMethodId;
|
||||
@override
|
||||
@JsonKey(name: "customer_id")
|
||||
final String? customerId;
|
||||
@override
|
||||
@JsonKey(name: "customer_name")
|
||||
final String? customerName;
|
||||
@override
|
||||
@JsonKey(name: "type")
|
||||
final String? type;
|
||||
// e.g., "AMOUNT" or "ITEM"
|
||||
@override
|
||||
@JsonKey(name: "amount")
|
||||
final int? amount;
|
||||
final List<PaymentItemSplitBillRequestDto>? _items;
|
||||
@override
|
||||
@JsonKey(name: "items")
|
||||
List<PaymentItemSplitBillRequestDto>? get items {
|
||||
final value = _items;
|
||||
if (value == null) return null;
|
||||
if (_items is EqualUnmodifiableListView) return _items;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(value);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PaymentSplitBillRequestDto(orderId: $orderId, paymentMethodId: $paymentMethodId, customerId: $customerId, customerName: $customerName, type: $type, amount: $amount, items: $items)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$PaymentSplitBillRequestDtoImpl &&
|
||||
(identical(other.orderId, orderId) || other.orderId == orderId) &&
|
||||
(identical(other.paymentMethodId, paymentMethodId) ||
|
||||
other.paymentMethodId == paymentMethodId) &&
|
||||
(identical(other.customerId, customerId) ||
|
||||
other.customerId == customerId) &&
|
||||
(identical(other.customerName, customerName) ||
|
||||
other.customerName == customerName) &&
|
||||
(identical(other.type, type) || other.type == type) &&
|
||||
(identical(other.amount, amount) || other.amount == amount) &&
|
||||
const DeepCollectionEquality().equals(other._items, _items));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
orderId,
|
||||
paymentMethodId,
|
||||
customerId,
|
||||
customerName,
|
||||
type,
|
||||
amount,
|
||||
const DeepCollectionEquality().hash(_items),
|
||||
);
|
||||
|
||||
/// Create a copy of PaymentSplitBillRequestDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$PaymentSplitBillRequestDtoImplCopyWith<_$PaymentSplitBillRequestDtoImpl>
|
||||
get copyWith =>
|
||||
__$$PaymentSplitBillRequestDtoImplCopyWithImpl<
|
||||
_$PaymentSplitBillRequestDtoImpl
|
||||
>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$PaymentSplitBillRequestDtoImplToJson(this);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _PaymentSplitBillRequestDto extends PaymentSplitBillRequestDto {
|
||||
const factory _PaymentSplitBillRequestDto({
|
||||
@JsonKey(name: "order_id") final String? orderId,
|
||||
@JsonKey(name: "payment_method_id") final String? paymentMethodId,
|
||||
@JsonKey(name: "customer_id") final String? customerId,
|
||||
@JsonKey(name: "customer_name") final String? customerName,
|
||||
@JsonKey(name: "type") final String? type,
|
||||
@JsonKey(name: "amount") final int? amount,
|
||||
@JsonKey(name: "items") final List<PaymentItemSplitBillRequestDto>? items,
|
||||
}) = _$PaymentSplitBillRequestDtoImpl;
|
||||
const _PaymentSplitBillRequestDto._() : super._();
|
||||
|
||||
factory _PaymentSplitBillRequestDto.fromJson(Map<String, dynamic> json) =
|
||||
_$PaymentSplitBillRequestDtoImpl.fromJson;
|
||||
|
||||
@override
|
||||
@JsonKey(name: "order_id")
|
||||
String? get orderId;
|
||||
@override
|
||||
@JsonKey(name: "payment_method_id")
|
||||
String? get paymentMethodId;
|
||||
@override
|
||||
@JsonKey(name: "customer_id")
|
||||
String? get customerId;
|
||||
@override
|
||||
@JsonKey(name: "customer_name")
|
||||
String? get customerName;
|
||||
@override
|
||||
@JsonKey(name: "type")
|
||||
String? get type; // e.g., "AMOUNT" or "ITEM"
|
||||
@override
|
||||
@JsonKey(name: "amount")
|
||||
int? get amount;
|
||||
@override
|
||||
@JsonKey(name: "items")
|
||||
List<PaymentItemSplitBillRequestDto>? get items;
|
||||
|
||||
/// Create a copy of PaymentSplitBillRequestDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$PaymentSplitBillRequestDtoImplCopyWith<_$PaymentSplitBillRequestDtoImpl>
|
||||
get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
PaymentItemSplitBillRequestDto _$PaymentItemSplitBillRequestDtoFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) {
|
||||
return _PaymentItemSplitBillRequestDto.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$PaymentItemSplitBillRequestDto {
|
||||
@JsonKey(name: "order_item_id")
|
||||
String? get orderItemId => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "quantity")
|
||||
int? get quantity => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this PaymentItemSplitBillRequestDto to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of PaymentItemSplitBillRequestDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$PaymentItemSplitBillRequestDtoCopyWith<PaymentItemSplitBillRequestDto>
|
||||
get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $PaymentItemSplitBillRequestDtoCopyWith<$Res> {
|
||||
factory $PaymentItemSplitBillRequestDtoCopyWith(
|
||||
PaymentItemSplitBillRequestDto value,
|
||||
$Res Function(PaymentItemSplitBillRequestDto) then,
|
||||
) =
|
||||
_$PaymentItemSplitBillRequestDtoCopyWithImpl<
|
||||
$Res,
|
||||
PaymentItemSplitBillRequestDto
|
||||
>;
|
||||
@useResult
|
||||
$Res call({
|
||||
@JsonKey(name: "order_item_id") String? orderItemId,
|
||||
@JsonKey(name: "quantity") int? quantity,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$PaymentItemSplitBillRequestDtoCopyWithImpl<
|
||||
$Res,
|
||||
$Val extends PaymentItemSplitBillRequestDto
|
||||
>
|
||||
implements $PaymentItemSplitBillRequestDtoCopyWith<$Res> {
|
||||
_$PaymentItemSplitBillRequestDtoCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of PaymentItemSplitBillRequestDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({Object? orderItemId = freezed, Object? quantity = freezed}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
orderItemId: freezed == orderItemId
|
||||
? _value.orderItemId
|
||||
: orderItemId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
quantity: freezed == quantity
|
||||
? _value.quantity
|
||||
: quantity // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$PaymentItemSplitBillRequestDtoImplCopyWith<$Res>
|
||||
implements $PaymentItemSplitBillRequestDtoCopyWith<$Res> {
|
||||
factory _$$PaymentItemSplitBillRequestDtoImplCopyWith(
|
||||
_$PaymentItemSplitBillRequestDtoImpl value,
|
||||
$Res Function(_$PaymentItemSplitBillRequestDtoImpl) then,
|
||||
) = __$$PaymentItemSplitBillRequestDtoImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({
|
||||
@JsonKey(name: "order_item_id") String? orderItemId,
|
||||
@JsonKey(name: "quantity") int? quantity,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$PaymentItemSplitBillRequestDtoImplCopyWithImpl<$Res>
|
||||
extends
|
||||
_$PaymentItemSplitBillRequestDtoCopyWithImpl<
|
||||
$Res,
|
||||
_$PaymentItemSplitBillRequestDtoImpl
|
||||
>
|
||||
implements _$$PaymentItemSplitBillRequestDtoImplCopyWith<$Res> {
|
||||
__$$PaymentItemSplitBillRequestDtoImplCopyWithImpl(
|
||||
_$PaymentItemSplitBillRequestDtoImpl _value,
|
||||
$Res Function(_$PaymentItemSplitBillRequestDtoImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of PaymentItemSplitBillRequestDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({Object? orderItemId = freezed, Object? quantity = freezed}) {
|
||||
return _then(
|
||||
_$PaymentItemSplitBillRequestDtoImpl(
|
||||
orderItemId: freezed == orderItemId
|
||||
? _value.orderItemId
|
||||
: orderItemId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
quantity: freezed == quantity
|
||||
? _value.quantity
|
||||
: quantity // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$PaymentItemSplitBillRequestDtoImpl
|
||||
extends _PaymentItemSplitBillRequestDto {
|
||||
const _$PaymentItemSplitBillRequestDtoImpl({
|
||||
@JsonKey(name: "order_item_id") this.orderItemId,
|
||||
@JsonKey(name: "quantity") this.quantity,
|
||||
}) : super._();
|
||||
|
||||
factory _$PaymentItemSplitBillRequestDtoImpl.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _$$PaymentItemSplitBillRequestDtoImplFromJson(json);
|
||||
|
||||
@override
|
||||
@JsonKey(name: "order_item_id")
|
||||
final String? orderItemId;
|
||||
@override
|
||||
@JsonKey(name: "quantity")
|
||||
final int? quantity;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PaymentItemSplitBillRequestDto(orderItemId: $orderItemId, quantity: $quantity)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$PaymentItemSplitBillRequestDtoImpl &&
|
||||
(identical(other.orderItemId, orderItemId) ||
|
||||
other.orderItemId == orderItemId) &&
|
||||
(identical(other.quantity, quantity) ||
|
||||
other.quantity == quantity));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, orderItemId, quantity);
|
||||
|
||||
/// Create a copy of PaymentItemSplitBillRequestDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$PaymentItemSplitBillRequestDtoImplCopyWith<
|
||||
_$PaymentItemSplitBillRequestDtoImpl
|
||||
>
|
||||
get copyWith =>
|
||||
__$$PaymentItemSplitBillRequestDtoImplCopyWithImpl<
|
||||
_$PaymentItemSplitBillRequestDtoImpl
|
||||
>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$PaymentItemSplitBillRequestDtoImplToJson(this);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _PaymentItemSplitBillRequestDto
|
||||
extends PaymentItemSplitBillRequestDto {
|
||||
const factory _PaymentItemSplitBillRequestDto({
|
||||
@JsonKey(name: "order_item_id") final String? orderItemId,
|
||||
@JsonKey(name: "quantity") final int? quantity,
|
||||
}) = _$PaymentItemSplitBillRequestDtoImpl;
|
||||
const _PaymentItemSplitBillRequestDto._() : super._();
|
||||
|
||||
factory _PaymentItemSplitBillRequestDto.fromJson(Map<String, dynamic> json) =
|
||||
_$PaymentItemSplitBillRequestDtoImpl.fromJson;
|
||||
|
||||
@override
|
||||
@JsonKey(name: "order_item_id")
|
||||
String? get orderItemId;
|
||||
@override
|
||||
@JsonKey(name: "quantity")
|
||||
int? get quantity;
|
||||
|
||||
/// Create a copy of PaymentItemSplitBillRequestDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$PaymentItemSplitBillRequestDtoImplCopyWith<
|
||||
_$PaymentItemSplitBillRequestDtoImpl
|
||||
>
|
||||
get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
PaymentDto _$PaymentDtoFromJson(Map<String, dynamic> json) {
|
||||
return _PaymentOrderDto.fromJson(json);
|
||||
}
|
||||
|
||||
@@ -220,6 +220,49 @@ Map<String, dynamic> _$$PaymentItemRequestDtoImplToJson(
|
||||
'amount': instance.amount,
|
||||
};
|
||||
|
||||
_$PaymentSplitBillRequestDtoImpl _$$PaymentSplitBillRequestDtoImplFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _$PaymentSplitBillRequestDtoImpl(
|
||||
orderId: json['order_id'] as String?,
|
||||
paymentMethodId: json['payment_method_id'] as String?,
|
||||
customerId: json['customer_id'] as String?,
|
||||
customerName: json['customer_name'] as String?,
|
||||
type: json['type'] as String?,
|
||||
amount: (json['amount'] as num?)?.toInt(),
|
||||
items: (json['items'] as List<dynamic>?)
|
||||
?.map(
|
||||
(e) =>
|
||||
PaymentItemSplitBillRequestDto.fromJson(e as Map<String, dynamic>),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$PaymentSplitBillRequestDtoImplToJson(
|
||||
_$PaymentSplitBillRequestDtoImpl instance,
|
||||
) => <String, dynamic>{
|
||||
'order_id': instance.orderId,
|
||||
'payment_method_id': instance.paymentMethodId,
|
||||
'customer_id': instance.customerId,
|
||||
'customer_name': instance.customerName,
|
||||
'type': instance.type,
|
||||
'amount': instance.amount,
|
||||
'items': instance.items,
|
||||
};
|
||||
|
||||
_$PaymentItemSplitBillRequestDtoImpl
|
||||
_$$PaymentItemSplitBillRequestDtoImplFromJson(Map<String, dynamic> json) =>
|
||||
_$PaymentItemSplitBillRequestDtoImpl(
|
||||
orderItemId: json['order_item_id'] as String?,
|
||||
quantity: (json['quantity'] as num?)?.toInt(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$PaymentItemSplitBillRequestDtoImplToJson(
|
||||
_$PaymentItemSplitBillRequestDtoImpl instance,
|
||||
) => <String, dynamic>{
|
||||
'order_item_id': instance.orderItemId,
|
||||
'quantity': instance.quantity,
|
||||
};
|
||||
|
||||
_$PaymentOrderDtoImpl _$$PaymentOrderDtoImplFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _$PaymentOrderDtoImpl(
|
||||
|
||||
@@ -177,4 +177,25 @@ class OrderRepository implements IOrderRepository {
|
||||
return left(const OrderFailure.unexpectedError());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<OrderFailure, Payment>> createSplitBill(
|
||||
PaymentSplitBillRequest request,
|
||||
) async {
|
||||
try {
|
||||
final result = await _dataProvider.createSplitBill(
|
||||
PaymentSplitBillRequestDto.fromDomain(request),
|
||||
);
|
||||
|
||||
if (result.hasError) {
|
||||
return left(result.error!);
|
||||
}
|
||||
|
||||
final payment = result.data!.toDomain();
|
||||
return right(payment);
|
||||
} catch (e) {
|
||||
log('createSplitBillError', name: _logName, error: e);
|
||||
return left(const OrderFailure.unexpectedError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user