create order

This commit is contained in:
efrilm 2025-10-28 00:08:12 +07:00
parent 34555dd789
commit 37f0008ec8
21 changed files with 2028 additions and 108 deletions

View File

@ -1,17 +1,26 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart' hide Order;
import 'package:flutter/foundation.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import 'package:injectable/injectable.dart' hide Order;
import '../../../common/types/order_type.dart';
import '../../../domain/customer/customer.dart';
import '../../../domain/order/order.dart';
import '../../../domain/outlet/outlet.dart';
import '../../../domain/payment_method/payment_method.dart';
import '../../../domain/product/product.dart';
import '../../../domain/table/table.dart';
part 'order_form_event.dart';
part 'order_form_state.dart';
part 'order_form_bloc.freezed.dart';
@injectable
class OrderFormBloc extends Bloc<OrderFormEvent, OrderFormState> {
OrderFormBloc() : super(OrderFormState.initial()) {
final IOrderRepository _repository;
final IOutletRepository _outletRepository;
OrderFormBloc(this._repository, this._outletRepository)
: super(OrderFormState.initial()) {
on<OrderFormEvent>(_onOrderFormBloc);
}
@ -29,6 +38,43 @@ class OrderFormBloc extends Bloc<OrderFormEvent, OrderFormState> {
customerChanged: (e) async {
emit(state.copyWith(customer: e.customer));
},
createOrderWithPayment: (e) async {
Either<OrderFailure, Order> failureOrOrder;
emit(state.copyWith(isCreating: true, failureOrCreateOrder: none()));
final outlet = await _outletRepository.currentOutlet();
final request = OrderRequest(
outletId: outlet.id,
customerId: state.customer?.id ?? '',
tableNumber: e.table?.tableName ?? '',
tableId: e.table?.id ?? '',
orderType: e.orderType.name,
notes: '',
customerName: state.customerName ?? "",
orderItems: e.items
.map(
(item) => OrderItemRequest(
productId: item.product.id,
productVariantId: item.variant?.id ?? "",
quantity: item.quantity,
unitPrice: item.product.price.toInt(),
notes: item.notes,
),
)
.toList(),
);
failureOrOrder = await _repository.createOrder(request: request);
emit(
state.copyWith(
isCreating: false,
failureOrCreateOrder: optionOf(failureOrOrder),
),
);
},
);
}
}

View File

@ -22,37 +22,59 @@ mixin _$OrderFormEvent {
required TResult Function(String customerName) customerNameChanged,
required TResult Function(PaymentMethod payment) paymentMethodChanged,
required TResult Function(Customer? customer) customerChanged,
required TResult Function(
List<ProductQuantity> items,
OrderType orderType,
Table? table,
)
createOrderWithPayment,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String customerName)? customerNameChanged,
TResult? Function(PaymentMethod payment)? paymentMethodChanged,
TResult? Function(Customer? customer)? customerChanged,
TResult? Function(
List<ProductQuantity> items,
OrderType orderType,
Table? table,
)?
createOrderWithPayment,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String customerName)? customerNameChanged,
TResult Function(PaymentMethod payment)? paymentMethodChanged,
TResult Function(Customer? customer)? customerChanged,
TResult Function(
List<ProductQuantity> items,
OrderType orderType,
Table? table,
)?
createOrderWithPayment,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_CustomerNameChanged value) customerNameChanged,
required TResult Function(_PaymentMethodChanged value) paymentMethodChanged,
required TResult Function(_CustomeChanged value) customerChanged,
required TResult Function(_CustomerChanged value) customerChanged,
required TResult Function(_CreateOrderWithPayment value)
createOrderWithPayment,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_CustomerNameChanged value)? customerNameChanged,
TResult? Function(_PaymentMethodChanged value)? paymentMethodChanged,
TResult? Function(_CustomeChanged value)? customerChanged,
TResult? Function(_CustomerChanged value)? customerChanged,
TResult? Function(_CreateOrderWithPayment value)? createOrderWithPayment,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_CustomerNameChanged value)? customerNameChanged,
TResult Function(_PaymentMethodChanged value)? paymentMethodChanged,
TResult Function(_CustomeChanged value)? customerChanged,
TResult Function(_CustomerChanged value)? customerChanged,
TResult Function(_CreateOrderWithPayment value)? createOrderWithPayment,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
}
@ -166,6 +188,12 @@ class _$CustomerNameChangedImpl
required TResult Function(String customerName) customerNameChanged,
required TResult Function(PaymentMethod payment) paymentMethodChanged,
required TResult Function(Customer? customer) customerChanged,
required TResult Function(
List<ProductQuantity> items,
OrderType orderType,
Table? table,
)
createOrderWithPayment,
}) {
return customerNameChanged(customerName);
}
@ -176,6 +204,12 @@ class _$CustomerNameChangedImpl
TResult? Function(String customerName)? customerNameChanged,
TResult? Function(PaymentMethod payment)? paymentMethodChanged,
TResult? Function(Customer? customer)? customerChanged,
TResult? Function(
List<ProductQuantity> items,
OrderType orderType,
Table? table,
)?
createOrderWithPayment,
}) {
return customerNameChanged?.call(customerName);
}
@ -186,6 +220,12 @@ class _$CustomerNameChangedImpl
TResult Function(String customerName)? customerNameChanged,
TResult Function(PaymentMethod payment)? paymentMethodChanged,
TResult Function(Customer? customer)? customerChanged,
TResult Function(
List<ProductQuantity> items,
OrderType orderType,
Table? table,
)?
createOrderWithPayment,
required TResult orElse(),
}) {
if (customerNameChanged != null) {
@ -199,7 +239,9 @@ class _$CustomerNameChangedImpl
TResult map<TResult extends Object?>({
required TResult Function(_CustomerNameChanged value) customerNameChanged,
required TResult Function(_PaymentMethodChanged value) paymentMethodChanged,
required TResult Function(_CustomeChanged value) customerChanged,
required TResult Function(_CustomerChanged value) customerChanged,
required TResult Function(_CreateOrderWithPayment value)
createOrderWithPayment,
}) {
return customerNameChanged(this);
}
@ -209,7 +251,8 @@ class _$CustomerNameChangedImpl
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_CustomerNameChanged value)? customerNameChanged,
TResult? Function(_PaymentMethodChanged value)? paymentMethodChanged,
TResult? Function(_CustomeChanged value)? customerChanged,
TResult? Function(_CustomerChanged value)? customerChanged,
TResult? Function(_CreateOrderWithPayment value)? createOrderWithPayment,
}) {
return customerNameChanged?.call(this);
}
@ -219,7 +262,8 @@ class _$CustomerNameChangedImpl
TResult maybeMap<TResult extends Object?>({
TResult Function(_CustomerNameChanged value)? customerNameChanged,
TResult Function(_PaymentMethodChanged value)? paymentMethodChanged,
TResult Function(_CustomeChanged value)? customerChanged,
TResult Function(_CustomerChanged value)? customerChanged,
TResult Function(_CreateOrderWithPayment value)? createOrderWithPayment,
required TResult orElse(),
}) {
if (customerNameChanged != null) {
@ -341,6 +385,12 @@ class _$PaymentMethodChangedImpl
required TResult Function(String customerName) customerNameChanged,
required TResult Function(PaymentMethod payment) paymentMethodChanged,
required TResult Function(Customer? customer) customerChanged,
required TResult Function(
List<ProductQuantity> items,
OrderType orderType,
Table? table,
)
createOrderWithPayment,
}) {
return paymentMethodChanged(payment);
}
@ -351,6 +401,12 @@ class _$PaymentMethodChangedImpl
TResult? Function(String customerName)? customerNameChanged,
TResult? Function(PaymentMethod payment)? paymentMethodChanged,
TResult? Function(Customer? customer)? customerChanged,
TResult? Function(
List<ProductQuantity> items,
OrderType orderType,
Table? table,
)?
createOrderWithPayment,
}) {
return paymentMethodChanged?.call(payment);
}
@ -361,6 +417,12 @@ class _$PaymentMethodChangedImpl
TResult Function(String customerName)? customerNameChanged,
TResult Function(PaymentMethod payment)? paymentMethodChanged,
TResult Function(Customer? customer)? customerChanged,
TResult Function(
List<ProductQuantity> items,
OrderType orderType,
Table? table,
)?
createOrderWithPayment,
required TResult orElse(),
}) {
if (paymentMethodChanged != null) {
@ -374,7 +436,9 @@ class _$PaymentMethodChangedImpl
TResult map<TResult extends Object?>({
required TResult Function(_CustomerNameChanged value) customerNameChanged,
required TResult Function(_PaymentMethodChanged value) paymentMethodChanged,
required TResult Function(_CustomeChanged value) customerChanged,
required TResult Function(_CustomerChanged value) customerChanged,
required TResult Function(_CreateOrderWithPayment value)
createOrderWithPayment,
}) {
return paymentMethodChanged(this);
}
@ -384,7 +448,8 @@ class _$PaymentMethodChangedImpl
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_CustomerNameChanged value)? customerNameChanged,
TResult? Function(_PaymentMethodChanged value)? paymentMethodChanged,
TResult? Function(_CustomeChanged value)? customerChanged,
TResult? Function(_CustomerChanged value)? customerChanged,
TResult? Function(_CreateOrderWithPayment value)? createOrderWithPayment,
}) {
return paymentMethodChanged?.call(this);
}
@ -394,7 +459,8 @@ class _$PaymentMethodChangedImpl
TResult maybeMap<TResult extends Object?>({
TResult Function(_CustomerNameChanged value)? customerNameChanged,
TResult Function(_PaymentMethodChanged value)? paymentMethodChanged,
TResult Function(_CustomeChanged value)? customerChanged,
TResult Function(_CustomerChanged value)? customerChanged,
TResult Function(_CreateOrderWithPayment value)? createOrderWithPayment,
required TResult orElse(),
}) {
if (paymentMethodChanged != null) {
@ -418,11 +484,11 @@ abstract class _PaymentMethodChanged implements OrderFormEvent {
}
/// @nodoc
abstract class _$$CustomeChangedImplCopyWith<$Res> {
factory _$$CustomeChangedImplCopyWith(
_$CustomeChangedImpl value,
$Res Function(_$CustomeChangedImpl) then,
) = __$$CustomeChangedImplCopyWithImpl<$Res>;
abstract class _$$CustomerChangedImplCopyWith<$Res> {
factory _$$CustomerChangedImplCopyWith(
_$CustomerChangedImpl value,
$Res Function(_$CustomerChangedImpl) then,
) = __$$CustomerChangedImplCopyWithImpl<$Res>;
@useResult
$Res call({Customer? customer});
@ -430,12 +496,12 @@ abstract class _$$CustomeChangedImplCopyWith<$Res> {
}
/// @nodoc
class __$$CustomeChangedImplCopyWithImpl<$Res>
extends _$OrderFormEventCopyWithImpl<$Res, _$CustomeChangedImpl>
implements _$$CustomeChangedImplCopyWith<$Res> {
__$$CustomeChangedImplCopyWithImpl(
_$CustomeChangedImpl _value,
$Res Function(_$CustomeChangedImpl) _then,
class __$$CustomerChangedImplCopyWithImpl<$Res>
extends _$OrderFormEventCopyWithImpl<$Res, _$CustomerChangedImpl>
implements _$$CustomerChangedImplCopyWith<$Res> {
__$$CustomerChangedImplCopyWithImpl(
_$CustomerChangedImpl _value,
$Res Function(_$CustomerChangedImpl) _then,
) : super(_value, _then);
/// Create a copy of OrderFormEvent
@ -444,7 +510,7 @@ class __$$CustomeChangedImplCopyWithImpl<$Res>
@override
$Res call({Object? customer = freezed}) {
return _then(
_$CustomeChangedImpl(
_$CustomerChangedImpl(
freezed == customer
? _value.customer
: customer // ignore: cast_nullable_to_non_nullable
@ -470,10 +536,10 @@ class __$$CustomeChangedImplCopyWithImpl<$Res>
/// @nodoc
class _$CustomeChangedImpl
class _$CustomerChangedImpl
with DiagnosticableTreeMixin
implements _CustomeChanged {
const _$CustomeChangedImpl(this.customer);
implements _CustomerChanged {
const _$CustomerChangedImpl(this.customer);
@override
final Customer? customer;
@ -495,7 +561,7 @@ class _$CustomeChangedImpl
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$CustomeChangedImpl &&
other is _$CustomerChangedImpl &&
(identical(other.customer, customer) ||
other.customer == customer));
}
@ -508,8 +574,8 @@ class _$CustomeChangedImpl
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$CustomeChangedImplCopyWith<_$CustomeChangedImpl> get copyWith =>
__$$CustomeChangedImplCopyWithImpl<_$CustomeChangedImpl>(
_$$CustomerChangedImplCopyWith<_$CustomerChangedImpl> get copyWith =>
__$$CustomerChangedImplCopyWithImpl<_$CustomerChangedImpl>(
this,
_$identity,
);
@ -520,6 +586,12 @@ class _$CustomeChangedImpl
required TResult Function(String customerName) customerNameChanged,
required TResult Function(PaymentMethod payment) paymentMethodChanged,
required TResult Function(Customer? customer) customerChanged,
required TResult Function(
List<ProductQuantity> items,
OrderType orderType,
Table? table,
)
createOrderWithPayment,
}) {
return customerChanged(customer);
}
@ -530,6 +602,12 @@ class _$CustomeChangedImpl
TResult? Function(String customerName)? customerNameChanged,
TResult? Function(PaymentMethod payment)? paymentMethodChanged,
TResult? Function(Customer? customer)? customerChanged,
TResult? Function(
List<ProductQuantity> items,
OrderType orderType,
Table? table,
)?
createOrderWithPayment,
}) {
return customerChanged?.call(customer);
}
@ -540,6 +618,12 @@ class _$CustomeChangedImpl
TResult Function(String customerName)? customerNameChanged,
TResult Function(PaymentMethod payment)? paymentMethodChanged,
TResult Function(Customer? customer)? customerChanged,
TResult Function(
List<ProductQuantity> items,
OrderType orderType,
Table? table,
)?
createOrderWithPayment,
required TResult orElse(),
}) {
if (customerChanged != null) {
@ -553,7 +637,9 @@ class _$CustomeChangedImpl
TResult map<TResult extends Object?>({
required TResult Function(_CustomerNameChanged value) customerNameChanged,
required TResult Function(_PaymentMethodChanged value) paymentMethodChanged,
required TResult Function(_CustomeChanged value) customerChanged,
required TResult Function(_CustomerChanged value) customerChanged,
required TResult Function(_CreateOrderWithPayment value)
createOrderWithPayment,
}) {
return customerChanged(this);
}
@ -563,7 +649,8 @@ class _$CustomeChangedImpl
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_CustomerNameChanged value)? customerNameChanged,
TResult? Function(_PaymentMethodChanged value)? paymentMethodChanged,
TResult? Function(_CustomeChanged value)? customerChanged,
TResult? Function(_CustomerChanged value)? customerChanged,
TResult? Function(_CreateOrderWithPayment value)? createOrderWithPayment,
}) {
return customerChanged?.call(this);
}
@ -573,7 +660,8 @@ class _$CustomeChangedImpl
TResult maybeMap<TResult extends Object?>({
TResult Function(_CustomerNameChanged value)? customerNameChanged,
TResult Function(_PaymentMethodChanged value)? paymentMethodChanged,
TResult Function(_CustomeChanged value)? customerChanged,
TResult Function(_CustomerChanged value)? customerChanged,
TResult Function(_CreateOrderWithPayment value)? createOrderWithPayment,
required TResult orElse(),
}) {
if (customerChanged != null) {
@ -583,24 +671,271 @@ class _$CustomeChangedImpl
}
}
abstract class _CustomeChanged implements OrderFormEvent {
const factory _CustomeChanged(final Customer? customer) =
_$CustomeChangedImpl;
abstract class _CustomerChanged implements OrderFormEvent {
const factory _CustomerChanged(final Customer? customer) =
_$CustomerChangedImpl;
Customer? get customer;
/// Create a copy of OrderFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$CustomeChangedImplCopyWith<_$CustomeChangedImpl> get copyWith =>
_$$CustomerChangedImplCopyWith<_$CustomerChangedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class _$$CreateOrderWithPaymentImplCopyWith<$Res> {
factory _$$CreateOrderWithPaymentImplCopyWith(
_$CreateOrderWithPaymentImpl value,
$Res Function(_$CreateOrderWithPaymentImpl) then,
) = __$$CreateOrderWithPaymentImplCopyWithImpl<$Res>;
@useResult
$Res call({List<ProductQuantity> items, OrderType orderType, Table? table});
$TableCopyWith<$Res>? get table;
}
/// @nodoc
class __$$CreateOrderWithPaymentImplCopyWithImpl<$Res>
extends _$OrderFormEventCopyWithImpl<$Res, _$CreateOrderWithPaymentImpl>
implements _$$CreateOrderWithPaymentImplCopyWith<$Res> {
__$$CreateOrderWithPaymentImplCopyWithImpl(
_$CreateOrderWithPaymentImpl _value,
$Res Function(_$CreateOrderWithPaymentImpl) _then,
) : super(_value, _then);
/// Create a copy of OrderFormEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? items = null,
Object? orderType = null,
Object? table = freezed,
}) {
return _then(
_$CreateOrderWithPaymentImpl(
items: null == items
? _value._items
: items // ignore: cast_nullable_to_non_nullable
as List<ProductQuantity>,
orderType: null == orderType
? _value.orderType
: orderType // ignore: cast_nullable_to_non_nullable
as OrderType,
table: freezed == table
? _value.table
: table // ignore: cast_nullable_to_non_nullable
as Table?,
),
);
}
/// Create a copy of OrderFormEvent
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$TableCopyWith<$Res>? get table {
if (_value.table == null) {
return null;
}
return $TableCopyWith<$Res>(_value.table!, (value) {
return _then(_value.copyWith(table: value));
});
}
}
/// @nodoc
class _$CreateOrderWithPaymentImpl
with DiagnosticableTreeMixin
implements _CreateOrderWithPayment {
const _$CreateOrderWithPaymentImpl({
required final List<ProductQuantity> items,
required this.orderType,
this.table,
}) : _items = items;
final List<ProductQuantity> _items;
@override
List<ProductQuantity> get items {
if (_items is EqualUnmodifiableListView) return _items;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_items);
}
@override
final OrderType orderType;
@override
final Table? table;
@override
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
return 'OrderFormEvent.createOrderWithPayment(items: $items, orderType: $orderType, table: $table)';
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(
DiagnosticsProperty('type', 'OrderFormEvent.createOrderWithPayment'),
)
..add(DiagnosticsProperty('items', items))
..add(DiagnosticsProperty('orderType', orderType))
..add(DiagnosticsProperty('table', table));
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$CreateOrderWithPaymentImpl &&
const DeepCollectionEquality().equals(other._items, _items) &&
(identical(other.orderType, orderType) ||
other.orderType == orderType) &&
(identical(other.table, table) || other.table == table));
}
@override
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(_items),
orderType,
table,
);
/// Create a copy of OrderFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$CreateOrderWithPaymentImplCopyWith<_$CreateOrderWithPaymentImpl>
get copyWith =>
__$$CreateOrderWithPaymentImplCopyWithImpl<_$CreateOrderWithPaymentImpl>(
this,
_$identity,
);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String customerName) customerNameChanged,
required TResult Function(PaymentMethod payment) paymentMethodChanged,
required TResult Function(Customer? customer) customerChanged,
required TResult Function(
List<ProductQuantity> items,
OrderType orderType,
Table? table,
)
createOrderWithPayment,
}) {
return createOrderWithPayment(items, orderType, table);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String customerName)? customerNameChanged,
TResult? Function(PaymentMethod payment)? paymentMethodChanged,
TResult? Function(Customer? customer)? customerChanged,
TResult? Function(
List<ProductQuantity> items,
OrderType orderType,
Table? table,
)?
createOrderWithPayment,
}) {
return createOrderWithPayment?.call(items, orderType, table);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String customerName)? customerNameChanged,
TResult Function(PaymentMethod payment)? paymentMethodChanged,
TResult Function(Customer? customer)? customerChanged,
TResult Function(
List<ProductQuantity> items,
OrderType orderType,
Table? table,
)?
createOrderWithPayment,
required TResult orElse(),
}) {
if (createOrderWithPayment != null) {
return createOrderWithPayment(items, orderType, table);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_CustomerNameChanged value) customerNameChanged,
required TResult Function(_PaymentMethodChanged value) paymentMethodChanged,
required TResult Function(_CustomerChanged value) customerChanged,
required TResult Function(_CreateOrderWithPayment value)
createOrderWithPayment,
}) {
return createOrderWithPayment(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_CustomerNameChanged value)? customerNameChanged,
TResult? Function(_PaymentMethodChanged value)? paymentMethodChanged,
TResult? Function(_CustomerChanged value)? customerChanged,
TResult? Function(_CreateOrderWithPayment value)? createOrderWithPayment,
}) {
return createOrderWithPayment?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_CustomerNameChanged value)? customerNameChanged,
TResult Function(_PaymentMethodChanged value)? paymentMethodChanged,
TResult Function(_CustomerChanged value)? customerChanged,
TResult Function(_CreateOrderWithPayment value)? createOrderWithPayment,
required TResult orElse(),
}) {
if (createOrderWithPayment != null) {
return createOrderWithPayment(this);
}
return orElse();
}
}
abstract class _CreateOrderWithPayment implements OrderFormEvent {
const factory _CreateOrderWithPayment({
required final List<ProductQuantity> items,
required final OrderType orderType,
final Table? table,
}) = _$CreateOrderWithPaymentImpl;
List<ProductQuantity> get items;
OrderType get orderType;
Table? get table;
/// Create a copy of OrderFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$CreateOrderWithPaymentImplCopyWith<_$CreateOrderWithPaymentImpl>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$OrderFormState {
PaymentMethod? get paymentMethod => throw _privateConstructorUsedError;
String? get customerName => throw _privateConstructorUsedError;
Customer? get customer => throw _privateConstructorUsedError;
Option<Either<OrderFailure, Order>> get failureOrCreateOrder =>
throw _privateConstructorUsedError;
bool get isCreating => throw _privateConstructorUsedError;
/// Create a copy of OrderFormState
/// with the given fields replaced by the non-null parameter values.
@ -620,6 +955,8 @@ abstract class $OrderFormStateCopyWith<$Res> {
PaymentMethod? paymentMethod,
String? customerName,
Customer? customer,
Option<Either<OrderFailure, Order>> failureOrCreateOrder,
bool isCreating,
});
$PaymentMethodCopyWith<$Res>? get paymentMethod;
@ -644,6 +981,8 @@ class _$OrderFormStateCopyWithImpl<$Res, $Val extends OrderFormState>
Object? paymentMethod = freezed,
Object? customerName = freezed,
Object? customer = freezed,
Object? failureOrCreateOrder = null,
Object? isCreating = null,
}) {
return _then(
_value.copyWith(
@ -659,6 +998,14 @@ class _$OrderFormStateCopyWithImpl<$Res, $Val extends OrderFormState>
? _value.customer
: customer // ignore: cast_nullable_to_non_nullable
as Customer?,
failureOrCreateOrder: null == failureOrCreateOrder
? _value.failureOrCreateOrder
: failureOrCreateOrder // ignore: cast_nullable_to_non_nullable
as Option<Either<OrderFailure, Order>>,
isCreating: null == isCreating
? _value.isCreating
: isCreating // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
@ -706,6 +1053,8 @@ abstract class _$$OrderFormStateImplCopyWith<$Res>
PaymentMethod? paymentMethod,
String? customerName,
Customer? customer,
Option<Either<OrderFailure, Order>> failureOrCreateOrder,
bool isCreating,
});
@override
@ -731,6 +1080,8 @@ class __$$OrderFormStateImplCopyWithImpl<$Res>
Object? paymentMethod = freezed,
Object? customerName = freezed,
Object? customer = freezed,
Object? failureOrCreateOrder = null,
Object? isCreating = null,
}) {
return _then(
_$OrderFormStateImpl(
@ -746,6 +1097,14 @@ class __$$OrderFormStateImplCopyWithImpl<$Res>
? _value.customer
: customer // ignore: cast_nullable_to_non_nullable
as Customer?,
failureOrCreateOrder: null == failureOrCreateOrder
? _value.failureOrCreateOrder
: failureOrCreateOrder // ignore: cast_nullable_to_non_nullable
as Option<Either<OrderFailure, Order>>,
isCreating: null == isCreating
? _value.isCreating
: isCreating // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
@ -756,7 +1115,13 @@ class __$$OrderFormStateImplCopyWithImpl<$Res>
class _$OrderFormStateImpl
with DiagnosticableTreeMixin
implements _OrderFormState {
_$OrderFormStateImpl({this.paymentMethod, this.customerName, this.customer});
_$OrderFormStateImpl({
this.paymentMethod,
this.customerName,
this.customer,
required this.failureOrCreateOrder,
this.isCreating = false,
});
@override
final PaymentMethod? paymentMethod;
@ -764,10 +1129,15 @@ class _$OrderFormStateImpl
final String? customerName;
@override
final Customer? customer;
@override
final Option<Either<OrderFailure, Order>> failureOrCreateOrder;
@override
@JsonKey()
final bool isCreating;
@override
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
return 'OrderFormState(paymentMethod: $paymentMethod, customerName: $customerName, customer: $customer)';
return 'OrderFormState(paymentMethod: $paymentMethod, customerName: $customerName, customer: $customer, failureOrCreateOrder: $failureOrCreateOrder, isCreating: $isCreating)';
}
@override
@ -777,7 +1147,9 @@ class _$OrderFormStateImpl
..add(DiagnosticsProperty('type', 'OrderFormState'))
..add(DiagnosticsProperty('paymentMethod', paymentMethod))
..add(DiagnosticsProperty('customerName', customerName))
..add(DiagnosticsProperty('customer', customer));
..add(DiagnosticsProperty('customer', customer))
..add(DiagnosticsProperty('failureOrCreateOrder', failureOrCreateOrder))
..add(DiagnosticsProperty('isCreating', isCreating));
}
@override
@ -790,12 +1162,22 @@ class _$OrderFormStateImpl
(identical(other.customerName, customerName) ||
other.customerName == customerName) &&
(identical(other.customer, customer) ||
other.customer == customer));
other.customer == customer) &&
(identical(other.failureOrCreateOrder, failureOrCreateOrder) ||
other.failureOrCreateOrder == failureOrCreateOrder) &&
(identical(other.isCreating, isCreating) ||
other.isCreating == isCreating));
}
@override
int get hashCode =>
Object.hash(runtimeType, paymentMethod, customerName, customer);
int get hashCode => Object.hash(
runtimeType,
paymentMethod,
customerName,
customer,
failureOrCreateOrder,
isCreating,
);
/// Create a copy of OrderFormState
/// with the given fields replaced by the non-null parameter values.
@ -814,6 +1196,8 @@ abstract class _OrderFormState implements OrderFormState {
final PaymentMethod? paymentMethod,
final String? customerName,
final Customer? customer,
required final Option<Either<OrderFailure, Order>> failureOrCreateOrder,
final bool isCreating,
}) = _$OrderFormStateImpl;
@override
@ -822,6 +1206,10 @@ abstract class _OrderFormState implements OrderFormState {
String? get customerName;
@override
Customer? get customer;
@override
Option<Either<OrderFailure, Order>> get failureOrCreateOrder;
@override
bool get isCreating;
/// Create a copy of OrderFormState
/// with the given fields replaced by the non-null parameter values.

View File

@ -7,5 +7,10 @@ class OrderFormEvent with _$OrderFormEvent {
const factory OrderFormEvent.paymentMethodChanged(PaymentMethod payment) =
_PaymentMethodChanged;
const factory OrderFormEvent.customerChanged(Customer? customer) =
_CustomeChanged;
_CustomerChanged;
const factory OrderFormEvent.createOrderWithPayment({
required List<ProductQuantity> items,
required OrderType orderType,
Table? table,
}) = _CreateOrderWithPayment;
}

View File

@ -6,7 +6,10 @@ class OrderFormState with _$OrderFormState {
PaymentMethod? paymentMethod,
String? customerName,
Customer? customer,
required Option<Either<OrderFailure, Order>> failureOrCreateOrder,
@Default(false) bool isCreating,
}) = _OrderFormState;
factory OrderFormState.initial() => OrderFormState();
factory OrderFormState.initial() =>
OrderFormState(failureOrCreateOrder: none());
}

View File

@ -0,0 +1,45 @@
part of '../order.dart';
@freezed
class OrderRequest with _$OrderRequest {
const factory OrderRequest({
required String outletId,
required String customerId,
required String tableNumber,
required String tableId,
required String orderType,
required String notes,
required List<OrderItemRequest> orderItems,
required String customerName,
}) = _OrderRequest;
factory OrderRequest.empty() => const OrderRequest(
outletId: '',
customerId: '',
tableNumber: '',
tableId: '',
orderType: '',
notes: '',
orderItems: [],
customerName: '',
);
}
@freezed
class OrderItemRequest with _$OrderItemRequest {
const factory OrderItemRequest({
required String productId,
required String productVariantId,
required int quantity,
required int unitPrice,
required String notes,
}) = _OrderItemRequest;
factory OrderItemRequest.empty() => const OrderItemRequest(
productId: '',
productVariantId: '',
quantity: 0,
unitPrice: 0,
notes: '',
);
}

View File

@ -6,5 +6,6 @@ import '../../common/api/api_failure.dart';
part 'order.freezed.dart';
part 'entities/order_entity.dart';
part 'entities/order_request_entity.dart';
part 'failures/order_failure.dart';
part 'repositories/i_order_repository.dart';

View File

@ -1876,6 +1876,552 @@ abstract class _PaymentOrder implements PaymentOrder {
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$OrderRequest {
String get outletId => throw _privateConstructorUsedError;
String get customerId => throw _privateConstructorUsedError;
String get tableNumber => throw _privateConstructorUsedError;
String get tableId => throw _privateConstructorUsedError;
String get orderType => throw _privateConstructorUsedError;
String get notes => throw _privateConstructorUsedError;
List<OrderItemRequest> get orderItems => throw _privateConstructorUsedError;
String get customerName => throw _privateConstructorUsedError;
/// Create a copy of OrderRequest
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$OrderRequestCopyWith<OrderRequest> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $OrderRequestCopyWith<$Res> {
factory $OrderRequestCopyWith(
OrderRequest value,
$Res Function(OrderRequest) then,
) = _$OrderRequestCopyWithImpl<$Res, OrderRequest>;
@useResult
$Res call({
String outletId,
String customerId,
String tableNumber,
String tableId,
String orderType,
String notes,
List<OrderItemRequest> orderItems,
String customerName,
});
}
/// @nodoc
class _$OrderRequestCopyWithImpl<$Res, $Val extends OrderRequest>
implements $OrderRequestCopyWith<$Res> {
_$OrderRequestCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of OrderRequest
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? outletId = null,
Object? customerId = null,
Object? tableNumber = null,
Object? tableId = null,
Object? orderType = null,
Object? notes = null,
Object? orderItems = null,
Object? customerName = null,
}) {
return _then(
_value.copyWith(
outletId: null == outletId
? _value.outletId
: outletId // ignore: cast_nullable_to_non_nullable
as String,
customerId: null == customerId
? _value.customerId
: customerId // ignore: cast_nullable_to_non_nullable
as String,
tableNumber: null == tableNumber
? _value.tableNumber
: tableNumber // ignore: cast_nullable_to_non_nullable
as String,
tableId: null == tableId
? _value.tableId
: tableId // ignore: cast_nullable_to_non_nullable
as String,
orderType: null == orderType
? _value.orderType
: orderType // ignore: cast_nullable_to_non_nullable
as String,
notes: null == notes
? _value.notes
: notes // ignore: cast_nullable_to_non_nullable
as String,
orderItems: null == orderItems
? _value.orderItems
: orderItems // ignore: cast_nullable_to_non_nullable
as List<OrderItemRequest>,
customerName: null == customerName
? _value.customerName
: customerName // ignore: cast_nullable_to_non_nullable
as String,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$OrderRequestImplCopyWith<$Res>
implements $OrderRequestCopyWith<$Res> {
factory _$$OrderRequestImplCopyWith(
_$OrderRequestImpl value,
$Res Function(_$OrderRequestImpl) then,
) = __$$OrderRequestImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
String outletId,
String customerId,
String tableNumber,
String tableId,
String orderType,
String notes,
List<OrderItemRequest> orderItems,
String customerName,
});
}
/// @nodoc
class __$$OrderRequestImplCopyWithImpl<$Res>
extends _$OrderRequestCopyWithImpl<$Res, _$OrderRequestImpl>
implements _$$OrderRequestImplCopyWith<$Res> {
__$$OrderRequestImplCopyWithImpl(
_$OrderRequestImpl _value,
$Res Function(_$OrderRequestImpl) _then,
) : super(_value, _then);
/// Create a copy of OrderRequest
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? outletId = null,
Object? customerId = null,
Object? tableNumber = null,
Object? tableId = null,
Object? orderType = null,
Object? notes = null,
Object? orderItems = null,
Object? customerName = null,
}) {
return _then(
_$OrderRequestImpl(
outletId: null == outletId
? _value.outletId
: outletId // ignore: cast_nullable_to_non_nullable
as String,
customerId: null == customerId
? _value.customerId
: customerId // ignore: cast_nullable_to_non_nullable
as String,
tableNumber: null == tableNumber
? _value.tableNumber
: tableNumber // ignore: cast_nullable_to_non_nullable
as String,
tableId: null == tableId
? _value.tableId
: tableId // ignore: cast_nullable_to_non_nullable
as String,
orderType: null == orderType
? _value.orderType
: orderType // ignore: cast_nullable_to_non_nullable
as String,
notes: null == notes
? _value.notes
: notes // ignore: cast_nullable_to_non_nullable
as String,
orderItems: null == orderItems
? _value._orderItems
: orderItems // ignore: cast_nullable_to_non_nullable
as List<OrderItemRequest>,
customerName: null == customerName
? _value.customerName
: customerName // ignore: cast_nullable_to_non_nullable
as String,
),
);
}
}
/// @nodoc
class _$OrderRequestImpl implements _OrderRequest {
const _$OrderRequestImpl({
required this.outletId,
required this.customerId,
required this.tableNumber,
required this.tableId,
required this.orderType,
required this.notes,
required final List<OrderItemRequest> orderItems,
required this.customerName,
}) : _orderItems = orderItems;
@override
final String outletId;
@override
final String customerId;
@override
final String tableNumber;
@override
final String tableId;
@override
final String orderType;
@override
final String notes;
final List<OrderItemRequest> _orderItems;
@override
List<OrderItemRequest> get orderItems {
if (_orderItems is EqualUnmodifiableListView) return _orderItems;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_orderItems);
}
@override
final String customerName;
@override
String toString() {
return 'OrderRequest(outletId: $outletId, customerId: $customerId, tableNumber: $tableNumber, tableId: $tableId, orderType: $orderType, notes: $notes, orderItems: $orderItems, customerName: $customerName)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$OrderRequestImpl &&
(identical(other.outletId, outletId) ||
other.outletId == outletId) &&
(identical(other.customerId, customerId) ||
other.customerId == customerId) &&
(identical(other.tableNumber, tableNumber) ||
other.tableNumber == tableNumber) &&
(identical(other.tableId, tableId) || other.tableId == tableId) &&
(identical(other.orderType, orderType) ||
other.orderType == orderType) &&
(identical(other.notes, notes) || other.notes == notes) &&
const DeepCollectionEquality().equals(
other._orderItems,
_orderItems,
) &&
(identical(other.customerName, customerName) ||
other.customerName == customerName));
}
@override
int get hashCode => Object.hash(
runtimeType,
outletId,
customerId,
tableNumber,
tableId,
orderType,
notes,
const DeepCollectionEquality().hash(_orderItems),
customerName,
);
/// Create a copy of OrderRequest
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$OrderRequestImplCopyWith<_$OrderRequestImpl> get copyWith =>
__$$OrderRequestImplCopyWithImpl<_$OrderRequestImpl>(this, _$identity);
}
abstract class _OrderRequest implements OrderRequest {
const factory _OrderRequest({
required final String outletId,
required final String customerId,
required final String tableNumber,
required final String tableId,
required final String orderType,
required final String notes,
required final List<OrderItemRequest> orderItems,
required final String customerName,
}) = _$OrderRequestImpl;
@override
String get outletId;
@override
String get customerId;
@override
String get tableNumber;
@override
String get tableId;
@override
String get orderType;
@override
String get notes;
@override
List<OrderItemRequest> get orderItems;
@override
String get customerName;
/// Create a copy of OrderRequest
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$OrderRequestImplCopyWith<_$OrderRequestImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$OrderItemRequest {
String get productId => throw _privateConstructorUsedError;
String get productVariantId => throw _privateConstructorUsedError;
int get quantity => throw _privateConstructorUsedError;
int get unitPrice => throw _privateConstructorUsedError;
String get notes => throw _privateConstructorUsedError;
/// Create a copy of OrderItemRequest
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$OrderItemRequestCopyWith<OrderItemRequest> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $OrderItemRequestCopyWith<$Res> {
factory $OrderItemRequestCopyWith(
OrderItemRequest value,
$Res Function(OrderItemRequest) then,
) = _$OrderItemRequestCopyWithImpl<$Res, OrderItemRequest>;
@useResult
$Res call({
String productId,
String productVariantId,
int quantity,
int unitPrice,
String notes,
});
}
/// @nodoc
class _$OrderItemRequestCopyWithImpl<$Res, $Val extends OrderItemRequest>
implements $OrderItemRequestCopyWith<$Res> {
_$OrderItemRequestCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of OrderItemRequest
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? productId = null,
Object? productVariantId = null,
Object? quantity = null,
Object? unitPrice = null,
Object? notes = null,
}) {
return _then(
_value.copyWith(
productId: null == productId
? _value.productId
: productId // ignore: cast_nullable_to_non_nullable
as String,
productVariantId: null == productVariantId
? _value.productVariantId
: productVariantId // ignore: cast_nullable_to_non_nullable
as String,
quantity: null == quantity
? _value.quantity
: quantity // ignore: cast_nullable_to_non_nullable
as int,
unitPrice: null == unitPrice
? _value.unitPrice
: unitPrice // ignore: cast_nullable_to_non_nullable
as int,
notes: null == notes
? _value.notes
: notes // ignore: cast_nullable_to_non_nullable
as String,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$OrderItemRequestImplCopyWith<$Res>
implements $OrderItemRequestCopyWith<$Res> {
factory _$$OrderItemRequestImplCopyWith(
_$OrderItemRequestImpl value,
$Res Function(_$OrderItemRequestImpl) then,
) = __$$OrderItemRequestImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
String productId,
String productVariantId,
int quantity,
int unitPrice,
String notes,
});
}
/// @nodoc
class __$$OrderItemRequestImplCopyWithImpl<$Res>
extends _$OrderItemRequestCopyWithImpl<$Res, _$OrderItemRequestImpl>
implements _$$OrderItemRequestImplCopyWith<$Res> {
__$$OrderItemRequestImplCopyWithImpl(
_$OrderItemRequestImpl _value,
$Res Function(_$OrderItemRequestImpl) _then,
) : super(_value, _then);
/// Create a copy of OrderItemRequest
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? productId = null,
Object? productVariantId = null,
Object? quantity = null,
Object? unitPrice = null,
Object? notes = null,
}) {
return _then(
_$OrderItemRequestImpl(
productId: null == productId
? _value.productId
: productId // ignore: cast_nullable_to_non_nullable
as String,
productVariantId: null == productVariantId
? _value.productVariantId
: productVariantId // ignore: cast_nullable_to_non_nullable
as String,
quantity: null == quantity
? _value.quantity
: quantity // ignore: cast_nullable_to_non_nullable
as int,
unitPrice: null == unitPrice
? _value.unitPrice
: unitPrice // ignore: cast_nullable_to_non_nullable
as int,
notes: null == notes
? _value.notes
: notes // ignore: cast_nullable_to_non_nullable
as String,
),
);
}
}
/// @nodoc
class _$OrderItemRequestImpl implements _OrderItemRequest {
const _$OrderItemRequestImpl({
required this.productId,
required this.productVariantId,
required this.quantity,
required this.unitPrice,
required this.notes,
});
@override
final String productId;
@override
final String productVariantId;
@override
final int quantity;
@override
final int unitPrice;
@override
final String notes;
@override
String toString() {
return 'OrderItemRequest(productId: $productId, productVariantId: $productVariantId, quantity: $quantity, unitPrice: $unitPrice, notes: $notes)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$OrderItemRequestImpl &&
(identical(other.productId, productId) ||
other.productId == productId) &&
(identical(other.productVariantId, productVariantId) ||
other.productVariantId == productVariantId) &&
(identical(other.quantity, quantity) ||
other.quantity == quantity) &&
(identical(other.unitPrice, unitPrice) ||
other.unitPrice == unitPrice) &&
(identical(other.notes, notes) || other.notes == notes));
}
@override
int get hashCode => Object.hash(
runtimeType,
productId,
productVariantId,
quantity,
unitPrice,
notes,
);
/// Create a copy of OrderItemRequest
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$OrderItemRequestImplCopyWith<_$OrderItemRequestImpl> get copyWith =>
__$$OrderItemRequestImplCopyWithImpl<_$OrderItemRequestImpl>(
this,
_$identity,
);
}
abstract class _OrderItemRequest implements OrderItemRequest {
const factory _OrderItemRequest({
required final String productId,
required final String productVariantId,
required final int quantity,
required final int unitPrice,
required final String notes,
}) = _$OrderItemRequestImpl;
@override
String get productId;
@override
String get productVariantId;
@override
int get quantity;
@override
int get unitPrice;
@override
String get notes;
/// Create a copy of OrderItemRequest
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$OrderItemRequestImplCopyWith<_$OrderItemRequestImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$OrderFailure {
@optionalTypeArgs

View File

@ -9,4 +9,8 @@ abstract class IOrderRepository {
required DateTime endDate,
String? search,
});
Future<Either<OrderFailure, Order>> createOrder({
required OrderRequest request,
});
}

View File

@ -7,4 +7,6 @@ abstract class IOutletRepository {
});
Future<Either<OutletFailure, Outlet>> getOutletById(String id);
Future<Outlet> currentOutlet();
}

View File

@ -58,4 +58,29 @@ class OrderRemoteDataProvider {
return DC.error(OrderFailure.serverError(e));
}
}
Future<DC<OrderFailure, OrderDto>> storeOrder({
required OrderRequestDto request,
}) async {
try {
final response = await _apiClient.post(
ApiPath.orders,
data: request.toRequest(),
headers: getAuthorizationHeader(),
);
if (response.data['success'] == false) {
return DC.error(OrderFailure.unexpectedError());
}
final order = OrderDto.fromJson(
response.data['data'] as Map<String, dynamic>,
);
return DC.data(order);
} on ApiFailure catch (e, s) {
log('storeOrderError', name: _logName, error: e, stackTrace: s);
return DC.error(OrderFailure.serverError(e));
}
}
}

View File

@ -0,0 +1,108 @@
part of '../order_dtos.dart';
@freezed
class OrderRequestDto with _$OrderRequestDto {
const OrderRequestDto._();
const factory OrderRequestDto({
@JsonKey(name: "outlet_id") String? outletId,
@JsonKey(name: "customer_id") String? customerId,
@JsonKey(name: "table_number") String? tableNumber,
@JsonKey(name: "table_id") String? tableId,
@JsonKey(name: "order_type") String? orderType,
@JsonKey(name: "notes") String? notes,
@JsonKey(name: "order_items") List<OrderItemRequestDto>? orderItems,
@JsonKey(name: "customer_name") String? customerName,
}) = _OrderRequestDto;
factory OrderRequestDto.fromJson(Map<String, dynamic> json) =>
_$OrderRequestDtoFromJson(json);
// Optional: mapper ke domain entity
OrderRequest toDomain() => OrderRequest(
outletId: outletId ?? '',
customerId: customerId ?? '',
tableNumber: tableNumber ?? '',
tableId: tableId ?? '',
orderType: orderType ?? '',
notes: notes ?? '',
orderItems: orderItems?.map((e) => e.toDomain()).toList() ?? const [],
customerName: customerName ?? '',
);
factory OrderRequestDto.fromDomain(OrderRequest request) => OrderRequestDto(
outletId: request.outletId,
customerId: request.customerId,
tableNumber: request.tableNumber,
tableId: request.tableId,
orderType: request.orderType,
notes: request.notes,
orderItems: request.orderItems
.map((e) => OrderItemRequestDto.fromDomain(e))
.toList(),
customerName: request.customerName,
);
Map<String, dynamic> toRequest() {
Map<String, dynamic> data = {
"outlet_id": outletId,
"table_number": tableNumber,
"order_type": orderType,
"notes": notes,
"order_items": orderItems?.map((e) => e.toRequest()).toList(),
"customer_name": customerName,
};
if (customerId != null && customerId != '') {
data["customer_id"] = customerId;
}
if (tableId != null && tableId != '') {
data["table_id"] = tableId;
}
return data;
}
}
@freezed
class OrderItemRequestDto with _$OrderItemRequestDto {
const OrderItemRequestDto._();
const factory OrderItemRequestDto({
@JsonKey(name: "product_id") String? productId,
@JsonKey(name: "product_variant_id") String? productVariantId,
@JsonKey(name: "quantity") int? quantity,
@JsonKey(name: "unit_price") int? unitPrice,
@JsonKey(name: "notes") String? notes,
}) = _OrderItemRequestDto;
factory OrderItemRequestDto.fromJson(Map<String, dynamic> json) =>
_$OrderItemRequestDtoFromJson(json);
// Optional: mapper ke domain entity
OrderItemRequest toDomain() => OrderItemRequest(
productId: productId ?? '',
productVariantId: productVariantId ?? '',
quantity: quantity ?? 0,
unitPrice: unitPrice ?? 0,
notes: notes ?? '',
);
factory OrderItemRequestDto.fromDomain(OrderItemRequest request) =>
OrderItemRequestDto(
productId: request.productId,
productVariantId: request.productVariantId,
quantity: request.quantity,
unitPrice: request.unitPrice,
notes: request.notes,
);
Map<String, dynamic> toRequest() => {
"product_id": productId,
"product_variant_id": productVariantId,
"quantity": quantity,
"unit_price": unitPrice,
"notes": notes,
};
}

View File

@ -6,3 +6,4 @@ part 'order_dtos.freezed.dart';
part 'order_dtos.g.dart';
part 'dtos/order_dto.dart';
part 'dtos/order_request_dto.dart';

View File

@ -2163,3 +2163,635 @@ abstract class _PaymentOrderDto extends PaymentOrderDto {
_$$PaymentOrderDtoImplCopyWith<_$PaymentOrderDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
OrderRequestDto _$OrderRequestDtoFromJson(Map<String, dynamic> json) {
return _OrderRequestDto.fromJson(json);
}
/// @nodoc
mixin _$OrderRequestDto {
@JsonKey(name: "outlet_id")
String? get outletId => throw _privateConstructorUsedError;
@JsonKey(name: "customer_id")
String? get customerId => throw _privateConstructorUsedError;
@JsonKey(name: "table_number")
String? get tableNumber => throw _privateConstructorUsedError;
@JsonKey(name: "table_id")
String? get tableId => throw _privateConstructorUsedError;
@JsonKey(name: "order_type")
String? get orderType => throw _privateConstructorUsedError;
@JsonKey(name: "notes")
String? get notes => throw _privateConstructorUsedError;
@JsonKey(name: "order_items")
List<OrderItemRequestDto>? get orderItems =>
throw _privateConstructorUsedError;
@JsonKey(name: "customer_name")
String? get customerName => throw _privateConstructorUsedError;
/// Serializes this OrderRequestDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of OrderRequestDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$OrderRequestDtoCopyWith<OrderRequestDto> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $OrderRequestDtoCopyWith<$Res> {
factory $OrderRequestDtoCopyWith(
OrderRequestDto value,
$Res Function(OrderRequestDto) then,
) = _$OrderRequestDtoCopyWithImpl<$Res, OrderRequestDto>;
@useResult
$Res call({
@JsonKey(name: "outlet_id") String? outletId,
@JsonKey(name: "customer_id") String? customerId,
@JsonKey(name: "table_number") String? tableNumber,
@JsonKey(name: "table_id") String? tableId,
@JsonKey(name: "order_type") String? orderType,
@JsonKey(name: "notes") String? notes,
@JsonKey(name: "order_items") List<OrderItemRequestDto>? orderItems,
@JsonKey(name: "customer_name") String? customerName,
});
}
/// @nodoc
class _$OrderRequestDtoCopyWithImpl<$Res, $Val extends OrderRequestDto>
implements $OrderRequestDtoCopyWith<$Res> {
_$OrderRequestDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of OrderRequestDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? outletId = freezed,
Object? customerId = freezed,
Object? tableNumber = freezed,
Object? tableId = freezed,
Object? orderType = freezed,
Object? notes = freezed,
Object? orderItems = freezed,
Object? customerName = freezed,
}) {
return _then(
_value.copyWith(
outletId: freezed == outletId
? _value.outletId
: outletId // ignore: cast_nullable_to_non_nullable
as String?,
customerId: freezed == customerId
? _value.customerId
: customerId // ignore: cast_nullable_to_non_nullable
as String?,
tableNumber: freezed == tableNumber
? _value.tableNumber
: tableNumber // ignore: cast_nullable_to_non_nullable
as String?,
tableId: freezed == tableId
? _value.tableId
: tableId // ignore: cast_nullable_to_non_nullable
as String?,
orderType: freezed == orderType
? _value.orderType
: orderType // ignore: cast_nullable_to_non_nullable
as String?,
notes: freezed == notes
? _value.notes
: notes // ignore: cast_nullable_to_non_nullable
as String?,
orderItems: freezed == orderItems
? _value.orderItems
: orderItems // ignore: cast_nullable_to_non_nullable
as List<OrderItemRequestDto>?,
customerName: freezed == customerName
? _value.customerName
: customerName // ignore: cast_nullable_to_non_nullable
as String?,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$OrderRequestDtoImplCopyWith<$Res>
implements $OrderRequestDtoCopyWith<$Res> {
factory _$$OrderRequestDtoImplCopyWith(
_$OrderRequestDtoImpl value,
$Res Function(_$OrderRequestDtoImpl) then,
) = __$$OrderRequestDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
@JsonKey(name: "outlet_id") String? outletId,
@JsonKey(name: "customer_id") String? customerId,
@JsonKey(name: "table_number") String? tableNumber,
@JsonKey(name: "table_id") String? tableId,
@JsonKey(name: "order_type") String? orderType,
@JsonKey(name: "notes") String? notes,
@JsonKey(name: "order_items") List<OrderItemRequestDto>? orderItems,
@JsonKey(name: "customer_name") String? customerName,
});
}
/// @nodoc
class __$$OrderRequestDtoImplCopyWithImpl<$Res>
extends _$OrderRequestDtoCopyWithImpl<$Res, _$OrderRequestDtoImpl>
implements _$$OrderRequestDtoImplCopyWith<$Res> {
__$$OrderRequestDtoImplCopyWithImpl(
_$OrderRequestDtoImpl _value,
$Res Function(_$OrderRequestDtoImpl) _then,
) : super(_value, _then);
/// Create a copy of OrderRequestDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? outletId = freezed,
Object? customerId = freezed,
Object? tableNumber = freezed,
Object? tableId = freezed,
Object? orderType = freezed,
Object? notes = freezed,
Object? orderItems = freezed,
Object? customerName = freezed,
}) {
return _then(
_$OrderRequestDtoImpl(
outletId: freezed == outletId
? _value.outletId
: outletId // ignore: cast_nullable_to_non_nullable
as String?,
customerId: freezed == customerId
? _value.customerId
: customerId // ignore: cast_nullable_to_non_nullable
as String?,
tableNumber: freezed == tableNumber
? _value.tableNumber
: tableNumber // ignore: cast_nullable_to_non_nullable
as String?,
tableId: freezed == tableId
? _value.tableId
: tableId // ignore: cast_nullable_to_non_nullable
as String?,
orderType: freezed == orderType
? _value.orderType
: orderType // ignore: cast_nullable_to_non_nullable
as String?,
notes: freezed == notes
? _value.notes
: notes // ignore: cast_nullable_to_non_nullable
as String?,
orderItems: freezed == orderItems
? _value._orderItems
: orderItems // ignore: cast_nullable_to_non_nullable
as List<OrderItemRequestDto>?,
customerName: freezed == customerName
? _value.customerName
: customerName // ignore: cast_nullable_to_non_nullable
as String?,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$OrderRequestDtoImpl extends _OrderRequestDto {
const _$OrderRequestDtoImpl({
@JsonKey(name: "outlet_id") this.outletId,
@JsonKey(name: "customer_id") this.customerId,
@JsonKey(name: "table_number") this.tableNumber,
@JsonKey(name: "table_id") this.tableId,
@JsonKey(name: "order_type") this.orderType,
@JsonKey(name: "notes") this.notes,
@JsonKey(name: "order_items") final List<OrderItemRequestDto>? orderItems,
@JsonKey(name: "customer_name") this.customerName,
}) : _orderItems = orderItems,
super._();
factory _$OrderRequestDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$OrderRequestDtoImplFromJson(json);
@override
@JsonKey(name: "outlet_id")
final String? outletId;
@override
@JsonKey(name: "customer_id")
final String? customerId;
@override
@JsonKey(name: "table_number")
final String? tableNumber;
@override
@JsonKey(name: "table_id")
final String? tableId;
@override
@JsonKey(name: "order_type")
final String? orderType;
@override
@JsonKey(name: "notes")
final String? notes;
final List<OrderItemRequestDto>? _orderItems;
@override
@JsonKey(name: "order_items")
List<OrderItemRequestDto>? get orderItems {
final value = _orderItems;
if (value == null) return null;
if (_orderItems is EqualUnmodifiableListView) return _orderItems;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(value);
}
@override
@JsonKey(name: "customer_name")
final String? customerName;
@override
String toString() {
return 'OrderRequestDto(outletId: $outletId, customerId: $customerId, tableNumber: $tableNumber, tableId: $tableId, orderType: $orderType, notes: $notes, orderItems: $orderItems, customerName: $customerName)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$OrderRequestDtoImpl &&
(identical(other.outletId, outletId) ||
other.outletId == outletId) &&
(identical(other.customerId, customerId) ||
other.customerId == customerId) &&
(identical(other.tableNumber, tableNumber) ||
other.tableNumber == tableNumber) &&
(identical(other.tableId, tableId) || other.tableId == tableId) &&
(identical(other.orderType, orderType) ||
other.orderType == orderType) &&
(identical(other.notes, notes) || other.notes == notes) &&
const DeepCollectionEquality().equals(
other._orderItems,
_orderItems,
) &&
(identical(other.customerName, customerName) ||
other.customerName == customerName));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
outletId,
customerId,
tableNumber,
tableId,
orderType,
notes,
const DeepCollectionEquality().hash(_orderItems),
customerName,
);
/// Create a copy of OrderRequestDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$OrderRequestDtoImplCopyWith<_$OrderRequestDtoImpl> get copyWith =>
__$$OrderRequestDtoImplCopyWithImpl<_$OrderRequestDtoImpl>(
this,
_$identity,
);
@override
Map<String, dynamic> toJson() {
return _$$OrderRequestDtoImplToJson(this);
}
}
abstract class _OrderRequestDto extends OrderRequestDto {
const factory _OrderRequestDto({
@JsonKey(name: "outlet_id") final String? outletId,
@JsonKey(name: "customer_id") final String? customerId,
@JsonKey(name: "table_number") final String? tableNumber,
@JsonKey(name: "table_id") final String? tableId,
@JsonKey(name: "order_type") final String? orderType,
@JsonKey(name: "notes") final String? notes,
@JsonKey(name: "order_items") final List<OrderItemRequestDto>? orderItems,
@JsonKey(name: "customer_name") final String? customerName,
}) = _$OrderRequestDtoImpl;
const _OrderRequestDto._() : super._();
factory _OrderRequestDto.fromJson(Map<String, dynamic> json) =
_$OrderRequestDtoImpl.fromJson;
@override
@JsonKey(name: "outlet_id")
String? get outletId;
@override
@JsonKey(name: "customer_id")
String? get customerId;
@override
@JsonKey(name: "table_number")
String? get tableNumber;
@override
@JsonKey(name: "table_id")
String? get tableId;
@override
@JsonKey(name: "order_type")
String? get orderType;
@override
@JsonKey(name: "notes")
String? get notes;
@override
@JsonKey(name: "order_items")
List<OrderItemRequestDto>? get orderItems;
@override
@JsonKey(name: "customer_name")
String? get customerName;
/// Create a copy of OrderRequestDto
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$OrderRequestDtoImplCopyWith<_$OrderRequestDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
OrderItemRequestDto _$OrderItemRequestDtoFromJson(Map<String, dynamic> json) {
return _OrderItemRequestDto.fromJson(json);
}
/// @nodoc
mixin _$OrderItemRequestDto {
@JsonKey(name: "product_id")
String? get productId => throw _privateConstructorUsedError;
@JsonKey(name: "product_variant_id")
String? get productVariantId => throw _privateConstructorUsedError;
@JsonKey(name: "quantity")
int? get quantity => throw _privateConstructorUsedError;
@JsonKey(name: "unit_price")
int? get unitPrice => throw _privateConstructorUsedError;
@JsonKey(name: "notes")
String? get notes => throw _privateConstructorUsedError;
/// Serializes this OrderItemRequestDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of OrderItemRequestDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$OrderItemRequestDtoCopyWith<OrderItemRequestDto> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $OrderItemRequestDtoCopyWith<$Res> {
factory $OrderItemRequestDtoCopyWith(
OrderItemRequestDto value,
$Res Function(OrderItemRequestDto) then,
) = _$OrderItemRequestDtoCopyWithImpl<$Res, OrderItemRequestDto>;
@useResult
$Res call({
@JsonKey(name: "product_id") String? productId,
@JsonKey(name: "product_variant_id") String? productVariantId,
@JsonKey(name: "quantity") int? quantity,
@JsonKey(name: "unit_price") int? unitPrice,
@JsonKey(name: "notes") String? notes,
});
}
/// @nodoc
class _$OrderItemRequestDtoCopyWithImpl<$Res, $Val extends OrderItemRequestDto>
implements $OrderItemRequestDtoCopyWith<$Res> {
_$OrderItemRequestDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of OrderItemRequestDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? productId = freezed,
Object? productVariantId = freezed,
Object? quantity = freezed,
Object? unitPrice = freezed,
Object? notes = freezed,
}) {
return _then(
_value.copyWith(
productId: freezed == productId
? _value.productId
: productId // ignore: cast_nullable_to_non_nullable
as String?,
productVariantId: freezed == productVariantId
? _value.productVariantId
: productVariantId // ignore: cast_nullable_to_non_nullable
as String?,
quantity: freezed == quantity
? _value.quantity
: quantity // ignore: cast_nullable_to_non_nullable
as int?,
unitPrice: freezed == unitPrice
? _value.unitPrice
: unitPrice // ignore: cast_nullable_to_non_nullable
as int?,
notes: freezed == notes
? _value.notes
: notes // ignore: cast_nullable_to_non_nullable
as String?,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$OrderItemRequestDtoImplCopyWith<$Res>
implements $OrderItemRequestDtoCopyWith<$Res> {
factory _$$OrderItemRequestDtoImplCopyWith(
_$OrderItemRequestDtoImpl value,
$Res Function(_$OrderItemRequestDtoImpl) then,
) = __$$OrderItemRequestDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
@JsonKey(name: "product_id") String? productId,
@JsonKey(name: "product_variant_id") String? productVariantId,
@JsonKey(name: "quantity") int? quantity,
@JsonKey(name: "unit_price") int? unitPrice,
@JsonKey(name: "notes") String? notes,
});
}
/// @nodoc
class __$$OrderItemRequestDtoImplCopyWithImpl<$Res>
extends _$OrderItemRequestDtoCopyWithImpl<$Res, _$OrderItemRequestDtoImpl>
implements _$$OrderItemRequestDtoImplCopyWith<$Res> {
__$$OrderItemRequestDtoImplCopyWithImpl(
_$OrderItemRequestDtoImpl _value,
$Res Function(_$OrderItemRequestDtoImpl) _then,
) : super(_value, _then);
/// Create a copy of OrderItemRequestDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? productId = freezed,
Object? productVariantId = freezed,
Object? quantity = freezed,
Object? unitPrice = freezed,
Object? notes = freezed,
}) {
return _then(
_$OrderItemRequestDtoImpl(
productId: freezed == productId
? _value.productId
: productId // ignore: cast_nullable_to_non_nullable
as String?,
productVariantId: freezed == productVariantId
? _value.productVariantId
: productVariantId // ignore: cast_nullable_to_non_nullable
as String?,
quantity: freezed == quantity
? _value.quantity
: quantity // ignore: cast_nullable_to_non_nullable
as int?,
unitPrice: freezed == unitPrice
? _value.unitPrice
: unitPrice // ignore: cast_nullable_to_non_nullable
as int?,
notes: freezed == notes
? _value.notes
: notes // ignore: cast_nullable_to_non_nullable
as String?,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$OrderItemRequestDtoImpl extends _OrderItemRequestDto {
const _$OrderItemRequestDtoImpl({
@JsonKey(name: "product_id") this.productId,
@JsonKey(name: "product_variant_id") this.productVariantId,
@JsonKey(name: "quantity") this.quantity,
@JsonKey(name: "unit_price") this.unitPrice,
@JsonKey(name: "notes") this.notes,
}) : super._();
factory _$OrderItemRequestDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$OrderItemRequestDtoImplFromJson(json);
@override
@JsonKey(name: "product_id")
final String? productId;
@override
@JsonKey(name: "product_variant_id")
final String? productVariantId;
@override
@JsonKey(name: "quantity")
final int? quantity;
@override
@JsonKey(name: "unit_price")
final int? unitPrice;
@override
@JsonKey(name: "notes")
final String? notes;
@override
String toString() {
return 'OrderItemRequestDto(productId: $productId, productVariantId: $productVariantId, quantity: $quantity, unitPrice: $unitPrice, notes: $notes)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$OrderItemRequestDtoImpl &&
(identical(other.productId, productId) ||
other.productId == productId) &&
(identical(other.productVariantId, productVariantId) ||
other.productVariantId == productVariantId) &&
(identical(other.quantity, quantity) ||
other.quantity == quantity) &&
(identical(other.unitPrice, unitPrice) ||
other.unitPrice == unitPrice) &&
(identical(other.notes, notes) || other.notes == notes));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
productId,
productVariantId,
quantity,
unitPrice,
notes,
);
/// Create a copy of OrderItemRequestDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$OrderItemRequestDtoImplCopyWith<_$OrderItemRequestDtoImpl> get copyWith =>
__$$OrderItemRequestDtoImplCopyWithImpl<_$OrderItemRequestDtoImpl>(
this,
_$identity,
);
@override
Map<String, dynamic> toJson() {
return _$$OrderItemRequestDtoImplToJson(this);
}
}
abstract class _OrderItemRequestDto extends OrderItemRequestDto {
const factory _OrderItemRequestDto({
@JsonKey(name: "product_id") final String? productId,
@JsonKey(name: "product_variant_id") final String? productVariantId,
@JsonKey(name: "quantity") final int? quantity,
@JsonKey(name: "unit_price") final int? unitPrice,
@JsonKey(name: "notes") final String? notes,
}) = _$OrderItemRequestDtoImpl;
const _OrderItemRequestDto._() : super._();
factory _OrderItemRequestDto.fromJson(Map<String, dynamic> json) =
_$OrderItemRequestDtoImpl.fromJson;
@override
@JsonKey(name: "product_id")
String? get productId;
@override
@JsonKey(name: "product_variant_id")
String? get productVariantId;
@override
@JsonKey(name: "quantity")
int? get quantity;
@override
@JsonKey(name: "unit_price")
int? get unitPrice;
@override
@JsonKey(name: "notes")
String? get notes;
/// Create a copy of OrderItemRequestDto
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$OrderItemRequestDtoImplCopyWith<_$OrderItemRequestDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@ -167,3 +167,51 @@ Map<String, dynamic> _$$PaymentOrderDtoImplToJson(
'created_at': instance.createdAt,
'updated_at': instance.updatedAt,
};
_$OrderRequestDtoImpl _$$OrderRequestDtoImplFromJson(
Map<String, dynamic> json,
) => _$OrderRequestDtoImpl(
outletId: json['outlet_id'] as String?,
customerId: json['customer_id'] as String?,
tableNumber: json['table_number'] as String?,
tableId: json['table_id'] as String?,
orderType: json['order_type'] as String?,
notes: json['notes'] as String?,
orderItems: (json['order_items'] as List<dynamic>?)
?.map((e) => OrderItemRequestDto.fromJson(e as Map<String, dynamic>))
.toList(),
customerName: json['customer_name'] as String?,
);
Map<String, dynamic> _$$OrderRequestDtoImplToJson(
_$OrderRequestDtoImpl instance,
) => <String, dynamic>{
'outlet_id': instance.outletId,
'customer_id': instance.customerId,
'table_number': instance.tableNumber,
'table_id': instance.tableId,
'order_type': instance.orderType,
'notes': instance.notes,
'order_items': instance.orderItems,
'customer_name': instance.customerName,
};
_$OrderItemRequestDtoImpl _$$OrderItemRequestDtoImplFromJson(
Map<String, dynamic> json,
) => _$OrderItemRequestDtoImpl(
productId: json['product_id'] as String?,
productVariantId: json['product_variant_id'] as String?,
quantity: (json['quantity'] as num?)?.toInt(),
unitPrice: (json['unit_price'] as num?)?.toInt(),
notes: json['notes'] as String?,
);
Map<String, dynamic> _$$OrderItemRequestDtoImplToJson(
_$OrderItemRequestDtoImpl instance,
) => <String, dynamic>{
'product_id': instance.productId,
'product_variant_id': instance.productVariantId,
'quantity': instance.quantity,
'unit_price': instance.unitPrice,
'notes': instance.notes,
};

View File

@ -1,10 +1,11 @@
import 'dart:developer';
import 'package:dartz/dartz.dart';
import 'package:injectable/injectable.dart';
import 'package:dartz/dartz.dart' hide Order;
import 'package:injectable/injectable.dart' hide Order;
import '../../../domain/order/order.dart';
import '../datasources/remote_data_provider.dart';
import '../order_dtos.dart';
@Injectable(as: IOrderRepository)
class OrderRepository implements IOrderRepository {
@ -43,4 +44,25 @@ class OrderRepository implements IOrderRepository {
return left(const OrderFailure.unexpectedError());
}
}
@override
Future<Either<OrderFailure, Order>> createOrder({
required OrderRequest request,
}) async {
try {
final result = await _dataProvider.storeOrder(
request: OrderRequestDto.fromDomain(request),
);
if (result.hasError) {
return left(result.error!);
}
final order = result.data!.toDomain();
return right(order);
} catch (e) {
log('createOrderError', name: _logName, error: e);
return left(const OrderFailure.unexpectedError());
}
}
}

View File

@ -60,4 +60,10 @@ class OutletRepository implements IOutletRepository {
return left(const OutletFailure.unexpectedError());
}
}
@override
Future<Outlet> currentOutlet() async {
final result = await _localDataProvider.currentOutlet();
return result;
}
}

View File

@ -122,7 +122,6 @@ extension GetItInjectableX on _i174.GetIt {
preResolve: true,
);
gh.factory<_i13.CheckoutFormBloc>(() => _i13.CheckoutFormBloc());
gh.factory<_i702.OrderFormBloc>(() => _i702.OrderFormBloc());
gh.singleton<_i487.DatabaseHelper>(() => databaseDi.databaseHelper);
gh.lazySingleton<_i361.Dio>(() => dioDi.dio);
gh.lazySingleton<_i800.AppRouter>(() => autoRouteDi.appRouter);
@ -147,12 +146,18 @@ extension GetItInjectableX on _i174.GetIt {
() => _i457.ApiClient(gh<_i361.Dio>(), gh<_i923.Env>()),
);
gh.factory<_i923.Env>(() => _i923.ProdEnv(), registerFor: {_prod});
gh.factory<_i360.OrderRemoteDataProvider>(
() => _i360.OrderRemoteDataProvider(gh<_i457.ApiClient>()),
);
gh.factory<_i856.CategoryRemoteDataProvider>(
() => _i856.CategoryRemoteDataProvider(gh<_i457.ApiClient>()),
);
gh.factory<_i370.AuthRemoteDataProvider>(
() => _i370.AuthRemoteDataProvider(gh<_i457.ApiClient>()),
);
gh.factory<_i833.PaymentMethodRemoteDataProvider>(
() => _i833.PaymentMethodRemoteDataProvider(gh<_i457.ApiClient>()),
);
gh.factory<_i707.ProductRemoteDataProvider>(
() => _i707.ProductRemoteDataProvider(gh<_i457.ApiClient>()),
);
@ -165,12 +170,6 @@ extension GetItInjectableX on _i174.GetIt {
gh.factory<_i841.CustomerRemoteDataProvider>(
() => _i841.CustomerRemoteDataProvider(gh<_i457.ApiClient>()),
);
gh.factory<_i833.PaymentMethodRemoteDataProvider>(
() => _i833.PaymentMethodRemoteDataProvider(gh<_i457.ApiClient>()),
);
gh.factory<_i360.OrderRemoteDataProvider>(
() => _i360.OrderRemoteDataProvider(gh<_i457.ApiClient>()),
);
gh.factory<_i776.IAuthRepository>(
() => _i941.AuthRepository(
gh<_i370.AuthRemoteDataProvider>(),
@ -221,6 +220,12 @@ extension GetItInjectableX on _i174.GetIt {
gh.factory<_i1018.CategoryLoaderBloc>(
() => _i1018.CategoryLoaderBloc(gh<_i502.ICategoryRepository>()),
);
gh.factory<_i702.OrderFormBloc>(
() => _i702.OrderFormBloc(
gh<_i299.IOrderRepository>(),
gh<_i552.IOutletRepository>(),
),
);
gh.factory<_i143.ICustomerRepository>(
() => _i385.CustomerRepository(gh<_i841.CustomerRemoteDataProvider>()),
);

View File

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import '../../../common/theme/theme.dart';
import '../../../domain/auth/auth.dart';
import '../../../domain/order/order.dart';
import '../../../domain/table/table.dart';
class AppFlushbar {
@ -65,4 +66,18 @@ class AppFlushbar {
localStorageError: (value) => 'Terjadi kesalahan, silahkan coba lagi',
),
);
static void showOrderFailureToast(
BuildContext context,
OrderFailure failure,
) => showError(
context,
failure.map(
serverError: (value) => value.failure.toStringFormatted(context),
dynamicErrorMessage: (value) => value.erroMessage,
unexpectedError: (value) => 'Terjadi kesalahan, silahkan coba lagi',
empty: (value) => 'Tidak ada data',
localStorageError: (value) => 'Terjadi kesalahan, silahkan coba lagi',
),
);
}

View File

@ -3,10 +3,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../application/checkout/checkout_form/checkout_form_bloc.dart';
import '../../../application/order/order_form/order_form_bloc.dart';
import '../../../application/payment_method/payment_method_loader/payment_method_loader_bloc.dart';
import '../../../common/theme/theme.dart';
import '../../../injection.dart';
import '../../components/spaces/space.dart';
import '../../components/toast/flushbar.dart';
import 'widgets/checkout_left_panel.dart';
import 'widgets/checkout_right_panel.dart';
@ -16,43 +18,56 @@ class CheckoutPage extends StatelessWidget implements AutoRouteWrapper {
@override
Widget build(BuildContext context) {
return SafeArea(
child: Hero(
tag: 'checkout_screen',
child: BlocBuilder<CheckoutFormBloc, CheckoutFormState>(
builder: (context, state) {
final price = state.items.fold(
0,
(previousValue, element) =>
previousValue +
(element.product.price.toInt() +
(element.variant?.priceModifier.toInt() ?? 0)) *
element.quantity,
);
return BlocListener<OrderFormBloc, OrderFormState>(
listenWhen: (previous, current) =>
previous.failureOrCreateOrder != current.failureOrCreateOrder,
listener: (context, state) {
state.failureOrCreateOrder.fold(() {}, (either) {
either.fold((f) => AppFlushbar.showOrderFailureToast(context, f), (
order,
) {
if (context.mounted) {}
});
});
},
child: SafeArea(
child: Hero(
tag: 'checkout_screen',
child: BlocBuilder<CheckoutFormBloc, CheckoutFormState>(
builder: (context, state) {
final price = state.items.fold(
0,
(previousValue, element) =>
previousValue +
(element.product.price.toInt() +
(element.variant?.priceModifier.toInt() ?? 0)) *
element.quantity,
);
return Scaffold(
backgroundColor: AppColor.white,
body: Row(
children: [
Expanded(
flex: 3,
child: CheckoutLeftPanel(
checkoutState: state,
price: price,
return Scaffold(
backgroundColor: AppColor.white,
body: Row(
children: [
Expanded(
flex: 3,
child: CheckoutLeftPanel(
checkoutState: state,
price: price,
),
),
),
SpaceWidth(2),
Expanded(
flex: 3,
child: CheckoutRightPanel(
checkoutState: state,
price: price,
SpaceWidth(2),
Expanded(
flex: 3,
child: CheckoutRightPanel(
checkoutState: state,
price: price,
),
),
),
],
),
);
},
],
),
);
},
),
),
),
);

View File

@ -304,26 +304,27 @@ class _CheckoutRightPanelState extends State<CheckoutRightPanel> {
SpaceWidth(12),
Expanded(
child: AppElevatedButton.filled(
onPressed: () {
if (customerController.text == '') {
AppFlushbar.showError(
context,
'Pilih Pelanggan terlebih dahulu',
);
return;
}
isLoading: orderState.isCreating,
onPressed: orderState.isCreating
? null
: () {
if (customerController.text == '') {
AppFlushbar.showError(
context,
'Pilih Pelanggan terlebih dahulu',
);
return;
}
context.read<OrderFormBloc>().add(
OrderFormEvent.createOrderWithPayment(
items: widget.checkoutState.items,
orderType: widget.checkoutState.orderType,
table: widget.checkoutState.table,
),
);
},
// context.read<OrderFormBloc>().add(
// OrderFormEvent.createWithPayment(
// items: items,
// customerName: customerController.text,
// orderType: orderType,
// paymentMethod: selectedPaymentMethod!,
// table: widget.table,
// customer: selectedCustomer,
// ),
// );
},
label: 'Bayar',
),
),

View File

@ -32,7 +32,7 @@ import 'package:apskel_pos_flutter_v2/presentation/pages/splash/splash_page.dart
import 'package:apskel_pos_flutter_v2/presentation/pages/sync/sync_page.dart'
as _i10;
import 'package:auto_route/auto_route.dart' as _i12;
import 'package:flutter/widgets.dart' as _i13;
import 'package:flutter/material.dart' as _i13;
/// generated route for
/// [_i1.CheckoutPage]
@ -133,7 +133,9 @@ class OrderRoute extends _i12.PageRouteInfo<OrderRouteArgs> {
name,
builder: (data) {
final args = data.argsAs<OrderRouteArgs>();
return _i6.OrderPage(key: args.key, status: args.status);
return _i12.WrappedRoute(
child: _i6.OrderPage(key: args.key, status: args.status),
);
},
);
}