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
@@ -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));
}
}
}
@@ -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,
};
}
+1
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';
@@ -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;
}
@@ -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,
};
@@ -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());
}
}
}
@@ -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;
}
}