From 7090efb583ab852c652988b7682ef3f927551737 Mon Sep 17 00:00:00 2001 From: Achintha Isuru Date: Thu, 22 Jan 2026 15:52:28 -0500 Subject: [PATCH] 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. --- apps/mobile-client/.keep | 1 - apps/mobile-staff/.keep | 1 - .../lib/src/create_order_module.dart | 5 ++ .../client_create_order_repository_impl.dart | 62 ++++++++++++++++++ .../domain/entities/create_order_type.dart | 43 +++++++++++++ .../i_client_create_order_repository.dart | 5 ++ .../usecases/get_order_types_usecase.dart | 12 ++++ .../blocs/client_create_order_bloc.dart | 63 +++---------------- .../blocs/client_create_order_state.dart | 42 +------------ .../presentation/pages/create_order_page.dart | 1 + 10 files changed, 137 insertions(+), 98 deletions(-) delete mode 100644 apps/mobile-client/.keep delete mode 100644 apps/mobile-staff/.keep create mode 100644 apps/mobile/packages/features/client/create_order/lib/src/data/repositories/client_create_order_repository_impl.dart create mode 100644 apps/mobile/packages/features/client/create_order/lib/src/domain/entities/create_order_type.dart create mode 100644 apps/mobile/packages/features/client/create_order/lib/src/domain/repositories/i_client_create_order_repository.dart create mode 100644 apps/mobile/packages/features/client/create_order/lib/src/domain/usecases/get_order_types_usecase.dart diff --git a/apps/mobile-client/.keep b/apps/mobile-client/.keep deleted file mode 100644 index 8b137891..00000000 --- a/apps/mobile-client/.keep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/apps/mobile-staff/.keep b/apps/mobile-staff/.keep deleted file mode 100644 index 8b137891..00000000 --- a/apps/mobile-staff/.keep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/apps/mobile/packages/features/client/create_order/lib/src/create_order_module.dart b/apps/mobile/packages/features/client/create_order/lib/src/create_order_module.dart index 826ffc4b..4ac97077 100644 --- a/apps/mobile/packages/features/client/create_order/lib/src/create_order_module.dart +++ b/apps/mobile/packages/features/client/create_order/lib/src/create_order_module.dart @@ -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(ClientCreateOrderRepositoryImpl.new); + i.add(GetOrderTypesUseCase.new); i.addSingleton(ClientCreateOrderBloc.new); } diff --git a/apps/mobile/packages/features/client/create_order/lib/src/data/repositories/client_create_order_repository_impl.dart b/apps/mobile/packages/features/client/create_order/lib/src/data/repositories/client_create_order_repository_impl.dart new file mode 100644 index 00000000..bd179663 --- /dev/null +++ b/apps/mobile/packages/features/client/create_order/lib/src/data/repositories/client_create_order_repository_impl.dart @@ -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> 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, + ), + ]; + } +} diff --git a/apps/mobile/packages/features/client/create_order/lib/src/domain/entities/create_order_type.dart b/apps/mobile/packages/features/client/create_order/lib/src/domain/entities/create_order_type.dart new file mode 100644 index 00000000..2fe3d98d --- /dev/null +++ b/apps/mobile/packages/features/client/create_order/lib/src/domain/entities/create_order_type.dart @@ -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 get props => [ + id, + icon, + titleKey, + descriptionKey, + backgroundColor, + borderColor, + iconBackgroundColor, + iconColor, + textColor, + descriptionColor, + ]; +} diff --git a/apps/mobile/packages/features/client/create_order/lib/src/domain/repositories/i_client_create_order_repository.dart b/apps/mobile/packages/features/client/create_order/lib/src/domain/repositories/i_client_create_order_repository.dart new file mode 100644 index 00000000..4464df04 --- /dev/null +++ b/apps/mobile/packages/features/client/create_order/lib/src/domain/repositories/i_client_create_order_repository.dart @@ -0,0 +1,5 @@ +import '../entities/create_order_type.dart'; + +abstract interface class IClientCreateOrderRepository { + Future> getOrderTypes(); +} diff --git a/apps/mobile/packages/features/client/create_order/lib/src/domain/usecases/get_order_types_usecase.dart b/apps/mobile/packages/features/client/create_order/lib/src/domain/usecases/get_order_types_usecase.dart new file mode 100644 index 00000000..88037284 --- /dev/null +++ b/apps/mobile/packages/features/client/create_order/lib/src/domain/usecases/get_order_types_usecase.dart @@ -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> call() { + return _repository.getOrderTypes(); + } +} diff --git a/apps/mobile/packages/features/client/create_order/lib/src/presentation/blocs/client_create_order_bloc.dart b/apps/mobile/packages/features/client/create_order/lib/src/presentation/blocs/client_create_order_bloc.dart index 60f08bab..975e73fc 100644 --- a/apps/mobile/packages/features/client/create_order/lib/src/presentation/blocs/client_create_order_bloc.dart +++ b/apps/mobile/packages/features/client/create_order/lib/src/presentation/blocs/client_create_order_bloc.dart @@ -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 { - ClientCreateOrderBloc() : super(const ClientCreateOrderInitial()) { + final GetOrderTypesUseCase _getOrderTypesUseCase; + + ClientCreateOrderBloc(this._getOrderTypesUseCase) + : super(const ClientCreateOrderInitial()) { on(_onTypesRequested); } - void _onTypesRequested( + Future _onTypesRequested( ClientCreateOrderTypesRequested event, Emitter emit, - ) { - // In a real app, this might come from a repository or config - final List 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)); } } diff --git a/apps/mobile/packages/features/client/create_order/lib/src/presentation/blocs/client_create_order_state.dart b/apps/mobile/packages/features/client/create_order/lib/src/presentation/blocs/client_create_order_state.dart index d977c4c3..f6728810 100644 --- a/apps/mobile/packages/features/client/create_order/lib/src/presentation/blocs/client_create_order_state.dart +++ b/apps/mobile/packages/features/client/create_order/lib/src/presentation/blocs/client_create_order_state.dart @@ -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 get props => [ - id, - icon, - titleKey, - descriptionKey, - backgroundColor, - borderColor, - iconBackgroundColor, - iconColor, - textColor, - descriptionColor, - ]; -} - abstract class ClientCreateOrderState extends Equatable { const ClientCreateOrderState(); diff --git a/apps/mobile/packages/features/client/create_order/lib/src/presentation/pages/create_order_page.dart b/apps/mobile/packages/features/client/create_order/lib/src/presentation/pages/create_order_page.dart index 2687f435..4be2e501 100644 --- a/apps/mobile/packages/features/client/create_order/lib/src/presentation/pages/create_order_page.dart +++ b/apps/mobile/packages/features/client/create_order/lib/src/presentation/pages/create_order_page.dart @@ -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';