Refactor create order feature with repository pattern
Introduced domain entities, repository interface, and use case for order types in the client create order feature. Moved order type data and logic from the Bloc to a repository implementation. Updated module bindings and imports to support the new architecture, improving separation of concerns and maintainability.
This commit is contained in:
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_modular/flutter_modular.dart';
|
||||
import 'data/repositories/client_create_order_repository_impl.dart';
|
||||
import 'domain/repositories/i_client_create_order_repository.dart';
|
||||
import 'domain/usecases/get_order_types_usecase.dart';
|
||||
import 'presentation/blocs/client_create_order_bloc.dart';
|
||||
import 'presentation/pages/create_order_page.dart';
|
||||
import 'presentation/pages/one_time_order_page.dart';
|
||||
@@ -10,6 +13,8 @@ import 'presentation/pages/recurring_order_page.dart';
|
||||
class ClientCreateOrderModule extends Module {
|
||||
@override
|
||||
void binds(Injector i) {
|
||||
i.add<IClientCreateOrderRepository>(ClientCreateOrderRepositoryImpl.new);
|
||||
i.add<GetOrderTypesUseCase>(GetOrderTypesUseCase.new);
|
||||
i.addSingleton<ClientCreateOrderBloc>(ClientCreateOrderBloc.new);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import 'package:design_system/design_system.dart';
|
||||
import '../../domain/entities/create_order_type.dart';
|
||||
import '../../domain/repositories/i_client_create_order_repository.dart';
|
||||
|
||||
class ClientCreateOrderRepositoryImpl implements IClientCreateOrderRepository {
|
||||
@override
|
||||
Future<List<CreateOrderType>> getOrderTypes() async {
|
||||
// Simulating async data fetch
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
return [
|
||||
const CreateOrderType(
|
||||
id: 'rapid',
|
||||
icon: UiIcons.zap,
|
||||
titleKey: 'client_create_order.types.rapid',
|
||||
descriptionKey: 'client_create_order.types.rapid_desc',
|
||||
backgroundColor: UiColors.tagError,
|
||||
borderColor: UiColors.destructive,
|
||||
iconBackgroundColor: UiColors.tagError,
|
||||
iconColor: UiColors.destructive,
|
||||
textColor: UiColors.destructive,
|
||||
descriptionColor: UiColors.textError,
|
||||
),
|
||||
const CreateOrderType(
|
||||
id: 'one-time',
|
||||
icon: UiIcons.calendar,
|
||||
titleKey: 'client_create_order.types.one_time',
|
||||
descriptionKey: 'client_create_order.types.one_time_desc',
|
||||
backgroundColor: UiColors.tagInProgress,
|
||||
borderColor: UiColors.primary,
|
||||
iconBackgroundColor: UiColors.tagInProgress,
|
||||
iconColor: UiColors.primary,
|
||||
textColor: UiColors.primary,
|
||||
descriptionColor: UiColors.primary,
|
||||
),
|
||||
const CreateOrderType(
|
||||
id: 'recurring',
|
||||
icon: UiIcons.rotateCcw,
|
||||
titleKey: 'client_create_order.types.recurring',
|
||||
descriptionKey: 'client_create_order.types.recurring_desc',
|
||||
backgroundColor: UiColors.tagRefunded,
|
||||
borderColor: UiColors.primary,
|
||||
iconBackgroundColor: UiColors.tagRefunded,
|
||||
iconColor: UiColors.primary,
|
||||
textColor: UiColors.primary,
|
||||
descriptionColor: UiColors.textSecondary,
|
||||
),
|
||||
const CreateOrderType(
|
||||
id: 'permanent',
|
||||
icon: UiIcons.briefcase,
|
||||
titleKey: 'client_create_order.types.permanent',
|
||||
descriptionKey: 'client_create_order.types.permanent_desc',
|
||||
backgroundColor: UiColors.tagSuccess,
|
||||
borderColor: UiColors.textSuccess,
|
||||
iconBackgroundColor: UiColors.tagSuccess,
|
||||
iconColor: UiColors.textSuccess,
|
||||
textColor: UiColors.textSuccess,
|
||||
descriptionColor: UiColors.textSuccess,
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// Entity representing an Order Type.
|
||||
class CreateOrderType extends Equatable {
|
||||
final String id;
|
||||
final IconData icon;
|
||||
final String titleKey; // Key for translation
|
||||
final String descriptionKey; // Key for translation
|
||||
final Color backgroundColor;
|
||||
final Color borderColor;
|
||||
final Color iconBackgroundColor;
|
||||
final Color iconColor;
|
||||
final Color textColor;
|
||||
final Color descriptionColor;
|
||||
|
||||
const CreateOrderType({
|
||||
required this.id,
|
||||
required this.icon,
|
||||
required this.titleKey,
|
||||
required this.descriptionKey,
|
||||
required this.backgroundColor,
|
||||
required this.borderColor,
|
||||
required this.iconBackgroundColor,
|
||||
required this.iconColor,
|
||||
required this.textColor,
|
||||
required this.descriptionColor,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
icon,
|
||||
titleKey,
|
||||
descriptionKey,
|
||||
backgroundColor,
|
||||
borderColor,
|
||||
iconBackgroundColor,
|
||||
iconColor,
|
||||
textColor,
|
||||
descriptionColor,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import '../entities/create_order_type.dart';
|
||||
|
||||
abstract interface class IClientCreateOrderRepository {
|
||||
Future<List<CreateOrderType>> getOrderTypes();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import '../entities/create_order_type.dart';
|
||||
import '../repositories/i_client_create_order_repository.dart';
|
||||
|
||||
class GetOrderTypesUseCase {
|
||||
final IClientCreateOrderRepository _repository;
|
||||
|
||||
GetOrderTypesUseCase(this._repository);
|
||||
|
||||
Future<List<CreateOrderType>> call() {
|
||||
return _repository.getOrderTypes();
|
||||
}
|
||||
}
|
||||
@@ -1,69 +1,22 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:design_system/design_system.dart';
|
||||
import '../../domain/usecases/get_order_types_usecase.dart';
|
||||
import 'client_create_order_event.dart';
|
||||
import 'client_create_order_state.dart';
|
||||
|
||||
class ClientCreateOrderBloc
|
||||
extends Bloc<ClientCreateOrderEvent, ClientCreateOrderState> {
|
||||
ClientCreateOrderBloc() : super(const ClientCreateOrderInitial()) {
|
||||
final GetOrderTypesUseCase _getOrderTypesUseCase;
|
||||
|
||||
ClientCreateOrderBloc(this._getOrderTypesUseCase)
|
||||
: super(const ClientCreateOrderInitial()) {
|
||||
on<ClientCreateOrderTypesRequested>(_onTypesRequested);
|
||||
}
|
||||
|
||||
void _onTypesRequested(
|
||||
Future<void> _onTypesRequested(
|
||||
ClientCreateOrderTypesRequested event,
|
||||
Emitter<ClientCreateOrderState> emit,
|
||||
) {
|
||||
// In a real app, this might come from a repository or config
|
||||
final List<CreateOrderType> types = [
|
||||
const CreateOrderType(
|
||||
id: 'rapid',
|
||||
icon: UiIcons.zap,
|
||||
titleKey: 'client_create_order.types.rapid',
|
||||
descriptionKey: 'client_create_order.types.rapid_desc',
|
||||
backgroundColor: UiColors.tagError, // Red-ish background
|
||||
borderColor: UiColors.destructive, // Red border
|
||||
iconBackgroundColor: UiColors.tagError,
|
||||
iconColor: UiColors.destructive,
|
||||
textColor: UiColors.destructive,
|
||||
descriptionColor: UiColors.textError,
|
||||
),
|
||||
const CreateOrderType(
|
||||
id: 'one-time',
|
||||
icon: UiIcons.calendar,
|
||||
titleKey: 'client_create_order.types.one_time',
|
||||
descriptionKey: 'client_create_order.types.one_time_desc',
|
||||
backgroundColor: UiColors.tagInProgress, // Blue-ish
|
||||
borderColor: UiColors.primary,
|
||||
iconBackgroundColor: UiColors.tagInProgress,
|
||||
iconColor: UiColors.primary,
|
||||
textColor: UiColors.primary,
|
||||
descriptionColor: UiColors.primary,
|
||||
),
|
||||
const CreateOrderType(
|
||||
id: 'recurring',
|
||||
icon: UiIcons.rotateCcw,
|
||||
titleKey: 'client_create_order.types.recurring',
|
||||
descriptionKey: 'client_create_order.types.recurring_desc',
|
||||
backgroundColor: UiColors.tagRefunded, // Indigo-ish (Purple sub)
|
||||
borderColor: UiColors.primary, // No purple, use primary or mix
|
||||
iconBackgroundColor: UiColors.tagRefunded,
|
||||
iconColor: UiColors.primary,
|
||||
textColor: UiColors.primary,
|
||||
descriptionColor: UiColors.textSecondary,
|
||||
),
|
||||
const CreateOrderType(
|
||||
id: 'permanent',
|
||||
icon: UiIcons.briefcase,
|
||||
titleKey: 'client_create_order.types.permanent',
|
||||
descriptionKey: 'client_create_order.types.permanent_desc',
|
||||
backgroundColor: UiColors.tagSuccess, // Green
|
||||
borderColor: UiColors.textSuccess,
|
||||
iconBackgroundColor: UiColors.tagSuccess,
|
||||
iconColor: UiColors.textSuccess,
|
||||
textColor: UiColors.textSuccess,
|
||||
descriptionColor: UiColors.textSuccess,
|
||||
),
|
||||
];
|
||||
) async {
|
||||
final types = await _getOrderTypesUseCase();
|
||||
emit(ClientCreateOrderLoadSuccess(types));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,7 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../domain/entities/create_order_type.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Represents an available order type.
|
||||
class CreateOrderType extends Equatable {
|
||||
final String id;
|
||||
final IconData icon;
|
||||
final String titleKey; // Key for translation
|
||||
final String descriptionKey; // Key for translation
|
||||
final Color backgroundColor;
|
||||
final Color borderColor;
|
||||
final Color iconBackgroundColor;
|
||||
final Color iconColor;
|
||||
final Color textColor;
|
||||
final Color descriptionColor;
|
||||
|
||||
const CreateOrderType({
|
||||
required this.id,
|
||||
required this.icon,
|
||||
required this.titleKey,
|
||||
required this.descriptionKey,
|
||||
required this.backgroundColor,
|
||||
required this.borderColor,
|
||||
required this.iconBackgroundColor,
|
||||
required this.iconColor,
|
||||
required this.textColor,
|
||||
required this.descriptionColor,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
icon,
|
||||
titleKey,
|
||||
descriptionKey,
|
||||
backgroundColor,
|
||||
borderColor,
|
||||
iconBackgroundColor,
|
||||
iconColor,
|
||||
textColor,
|
||||
descriptionColor,
|
||||
];
|
||||
}
|
||||
|
||||
abstract class ClientCreateOrderState extends Equatable {
|
||||
const ClientCreateOrderState();
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:design_system/design_system.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_modular/flutter_modular.dart';
|
||||
import '../../domain/entities/create_order_type.dart';
|
||||
import '../blocs/client_create_order_bloc.dart';
|
||||
import '../blocs/client_create_order_event.dart';
|
||||
import '../blocs/client_create_order_state.dart';
|
||||
|
||||
Reference in New Issue
Block a user