From bfd6b5c3a07697184f6af8d4fb406c973c72b18a Mon Sep 17 00:00:00 2001 From: mohammad Date: Thu, 10 Jul 2025 11:25:35 +0300 Subject: [PATCH] Refactor booking system: replace BookingSystemService with BookableSystemService and update parameter handling for improved clarity --- ...ce.dart => remote_bookable_spaces_service.dart} | 12 +++++------- .../services/DebouncedBookingSystemService.dart | 14 ++++++-------- .../domain/services/bookable_system_service.dart | 8 ++++++++ .../domain/services/booking_system_service.dart | 8 -------- .../presentation/bloc/sidebar/sidebar_bloc.dart | 14 ++++++-------- .../presentation/view/widgets/booking_sidebar.dart | 4 ++-- 6 files changed, 27 insertions(+), 33 deletions(-) rename lib/pages/access_management/booking_system/data/services/{bookable_spaces_service.dart => remote_bookable_spaces_service.dart} (80%) create mode 100644 lib/pages/access_management/booking_system/domain/services/bookable_system_service.dart delete mode 100644 lib/pages/access_management/booking_system/domain/services/booking_system_service.dart diff --git a/lib/pages/access_management/booking_system/data/services/bookable_spaces_service.dart b/lib/pages/access_management/booking_system/data/services/remote_bookable_spaces_service.dart similarity index 80% rename from lib/pages/access_management/booking_system/data/services/bookable_spaces_service.dart rename to lib/pages/access_management/booking_system/data/services/remote_bookable_spaces_service.dart index 72efcc1b..3c2610db 100644 --- a/lib/pages/access_management/booking_system/data/services/bookable_spaces_service.dart +++ b/lib/pages/access_management/booking_system/data/services/remote_bookable_spaces_service.dart @@ -1,20 +1,20 @@ import 'package:dio/dio.dart'; +import 'package:syncrow_web/pages/access_management/booking_system/domain/load_bookable_spaces_param.dart'; import 'package:syncrow_web/pages/access_management/booking_system/domain/models/paginated_bookable_spaces.dart'; -import 'package:syncrow_web/pages/access_management/booking_system/domain/services/booking_system_service.dart'; -import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart'; +import 'package:syncrow_web/pages/access_management/booking_system/domain/services/bookable_system_service.dart'; import 'package:syncrow_web/services/api/api_exception.dart'; import 'package:syncrow_web/services/api/http_service.dart'; import 'package:syncrow_web/utils/constants/api_const.dart'; -class BookableSpacesService implements BookingSystemService { - const BookableSpacesService(this._httpService); +class RemoteBookableSpacesService implements BookableSystemService { + const RemoteBookableSpacesService(this._httpService); final HTTPService _httpService; static const _defaultErrorMessage = 'Failed to load bookable spaces'; @override Future getBookableSpaces({ - required LoadCommunitiesParam param, + required LoadBookableSpacesParam param, }) async { try { final response = await _httpService.get( @@ -28,8 +28,6 @@ class BookableSpacesService implements BookingSystemService { param.search.isNotEmpty && param.search != 'null') 'search': param.search, - if (param.includeSpaces != null) - 'includeSpaces': param.includeSpaces, }, expectedResponseModel: (json) { return PaginatedBookableSpaces.fromJson( diff --git a/lib/pages/access_management/booking_system/domain/services/DebouncedBookingSystemService.dart b/lib/pages/access_management/booking_system/domain/services/DebouncedBookingSystemService.dart index 66a2c01f..a251a9c1 100644 --- a/lib/pages/access_management/booking_system/domain/services/DebouncedBookingSystemService.dart +++ b/lib/pages/access_management/booking_system/domain/services/DebouncedBookingSystemService.dart @@ -1,11 +1,10 @@ import 'dart:async'; -import 'package:meta/meta.dart'; +import 'package:syncrow_web/pages/access_management/booking_system/domain/load_bookable_spaces_param.dart'; import 'package:syncrow_web/pages/access_management/booking_system/domain/models/paginated_bookable_spaces.dart'; -import 'package:syncrow_web/pages/access_management/booking_system/domain/services/booking_system_service.dart'; -import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart'; +import 'package:syncrow_web/pages/access_management/booking_system/domain/services/bookable_system_service.dart'; -class DebouncedBookingSystemService implements BookingSystemService { - final BookingSystemService _inner; +class DebouncedBookingSystemService implements BookableSystemService { + final BookableSystemService _inner; final Duration debounceDuration; Timer? _debounceTimer; @@ -18,12 +17,11 @@ class DebouncedBookingSystemService implements BookingSystemService { @override Future getBookableSpaces({ - required LoadCommunitiesParam param, + required LoadBookableSpacesParam param, }) { _debounceTimer?.cancel(); if (_lastCompleter != null && !_lastCompleter!.isCompleted) { - _lastCompleter! - .completeError(StateError("Cancelled by new search")); + _lastCompleter!.completeError(StateError("Cancelled by new search")); } final completer = Completer(); diff --git a/lib/pages/access_management/booking_system/domain/services/bookable_system_service.dart b/lib/pages/access_management/booking_system/domain/services/bookable_system_service.dart new file mode 100644 index 00000000..c3b0bfb7 --- /dev/null +++ b/lib/pages/access_management/booking_system/domain/services/bookable_system_service.dart @@ -0,0 +1,8 @@ +import 'package:syncrow_web/pages/access_management/booking_system/domain/load_bookable_spaces_param.dart'; +import 'package:syncrow_web/pages/access_management/booking_system/domain/models/paginated_bookable_spaces.dart'; + +abstract class BookableSystemService { + Future getBookableSpaces({ + required LoadBookableSpacesParam param, + }); +} diff --git a/lib/pages/access_management/booking_system/domain/services/booking_system_service.dart b/lib/pages/access_management/booking_system/domain/services/booking_system_service.dart deleted file mode 100644 index b6d82d23..00000000 --- a/lib/pages/access_management/booking_system/domain/services/booking_system_service.dart +++ /dev/null @@ -1,8 +0,0 @@ -import 'package:syncrow_web/pages/access_management/booking_system/domain/models/paginated_bookable_spaces.dart'; -import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart'; - -abstract class BookingSystemService { - Future getBookableSpaces({ - required LoadCommunitiesParam param, - }); -} diff --git a/lib/pages/access_management/booking_system/presentation/bloc/sidebar/sidebar_bloc.dart b/lib/pages/access_management/booking_system/presentation/bloc/sidebar/sidebar_bloc.dart index 874971de..1b6f41fa 100644 --- a/lib/pages/access_management/booking_system/presentation/bloc/sidebar/sidebar_bloc.dart +++ b/lib/pages/access_management/booking_system/presentation/bloc/sidebar/sidebar_bloc.dart @@ -1,12 +1,12 @@ import 'dart:async'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/access_management/booking_system/domain/services/booking_system_service.dart'; +import 'package:syncrow_web/pages/access_management/booking_system/domain/load_bookable_spaces_param.dart'; +import 'package:syncrow_web/pages/access_management/booking_system/domain/services/bookable_system_service.dart'; import 'package:syncrow_web/pages/access_management/booking_system/presentation/bloc/sidebar/sidebar_event.dart'; import 'package:syncrow_web/pages/access_management/booking_system/presentation/bloc/sidebar/sidebar_state.dart'; -import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart'; class SidebarBloc extends Bloc { - final BookingSystemService _bookingService; + final BookableSystemService _bookingService; int _currentPage = 1; final int _pageSize = 20; String _currentSearch = ''; @@ -35,7 +35,7 @@ class SidebarBloc extends Bloc { _currentSearch = ''; final paginatedSpaces = await _bookingService.getBookableSpaces( - param: LoadCommunitiesParam( + param: LoadBookableSpacesParam( page: _currentPage, size: _pageSize, search: _currentSearch, @@ -69,11 +69,10 @@ class SidebarBloc extends Bloc { _currentPage++; final paginatedSpaces = await _bookingService.getBookableSpaces( - param: LoadCommunitiesParam( + param: LoadBookableSpacesParam( page: _currentPage, size: _pageSize, search: _currentSearch, - // Add any other required params ), ); @@ -105,11 +104,10 @@ class SidebarBloc extends Bloc { _currentPage = 1; emit(state.copyWith(isLoading: true, errorMessage: null)); final paginatedSpaces = await _bookingService.getBookableSpaces( - param: LoadCommunitiesParam( + param: LoadBookableSpacesParam( page: _currentPage, size: _pageSize, search: _currentSearch, - // Add other fields if required ), ); emit(state.copyWith( diff --git a/lib/pages/access_management/booking_system/presentation/view/widgets/booking_sidebar.dart b/lib/pages/access_management/booking_system/presentation/view/widgets/booking_sidebar.dart index 778822f8..894e2030 100644 --- a/lib/pages/access_management/booking_system/presentation/view/widgets/booking_sidebar.dart +++ b/lib/pages/access_management/booking_system/presentation/view/widgets/booking_sidebar.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/flutter_svg.dart'; -import 'package:syncrow_web/pages/access_management/booking_system/data/services/bookable_spaces_service.dart'; +import 'package:syncrow_web/pages/access_management/booking_system/data/services/remote_bookable_spaces_service.dart'; import 'package:syncrow_web/pages/access_management/booking_system/domain/models/bookable_room.dart'; import 'package:syncrow_web/pages/access_management/booking_system/presentation/bloc/sidebar/sidebar_bloc.dart'; import 'package:syncrow_web/pages/access_management/booking_system/presentation/bloc/sidebar/sidebar_event.dart'; @@ -23,7 +23,7 @@ class BookingSidebar extends StatelessWidget { @override Widget build(BuildContext context) { return BlocProvider( - create: (context) => SidebarBloc(BookableSpacesService( + create: (context) => SidebarBloc(RemoteBookableSpacesService( HTTPService(), )) ..add(LoadBookableSpaces()),