Refactor booking system: replace BookingSystemService with BookableSystemService and update parameter handling for improved clarity

This commit is contained in:
mohammad
2025-07-10 11:25:35 +03:00
parent 2b638940ae
commit bfd6b5c3a0
6 changed files with 27 additions and 33 deletions

View File

@ -1,20 +1,20 @@
import 'package:dio/dio.dart'; 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/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/access_management/booking_system/domain/services/bookable_system_service.dart';
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart';
import 'package:syncrow_web/services/api/api_exception.dart'; import 'package:syncrow_web/services/api/api_exception.dart';
import 'package:syncrow_web/services/api/http_service.dart'; import 'package:syncrow_web/services/api/http_service.dart';
import 'package:syncrow_web/utils/constants/api_const.dart'; import 'package:syncrow_web/utils/constants/api_const.dart';
class BookableSpacesService implements BookingSystemService { class RemoteBookableSpacesService implements BookableSystemService {
const BookableSpacesService(this._httpService); const RemoteBookableSpacesService(this._httpService);
final HTTPService _httpService; final HTTPService _httpService;
static const _defaultErrorMessage = 'Failed to load bookable spaces'; static const _defaultErrorMessage = 'Failed to load bookable spaces';
@override @override
Future<PaginatedBookableSpaces> getBookableSpaces({ Future<PaginatedBookableSpaces> getBookableSpaces({
required LoadCommunitiesParam param, required LoadBookableSpacesParam param,
}) async { }) async {
try { try {
final response = await _httpService.get( final response = await _httpService.get(
@ -28,8 +28,6 @@ class BookableSpacesService implements BookingSystemService {
param.search.isNotEmpty && param.search.isNotEmpty &&
param.search != 'null') param.search != 'null')
'search': param.search, 'search': param.search,
if (param.includeSpaces != null)
'includeSpaces': param.includeSpaces,
}, },
expectedResponseModel: (json) { expectedResponseModel: (json) {
return PaginatedBookableSpaces.fromJson( return PaginatedBookableSpaces.fromJson(

View File

@ -1,11 +1,10 @@
import 'dart:async'; 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/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/access_management/booking_system/domain/services/bookable_system_service.dart';
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart';
class DebouncedBookingSystemService implements BookingSystemService { class DebouncedBookingSystemService implements BookableSystemService {
final BookingSystemService _inner; final BookableSystemService _inner;
final Duration debounceDuration; final Duration debounceDuration;
Timer? _debounceTimer; Timer? _debounceTimer;
@ -18,12 +17,11 @@ class DebouncedBookingSystemService implements BookingSystemService {
@override @override
Future<PaginatedBookableSpaces> getBookableSpaces({ Future<PaginatedBookableSpaces> getBookableSpaces({
required LoadCommunitiesParam param, required LoadBookableSpacesParam param,
}) { }) {
_debounceTimer?.cancel(); _debounceTimer?.cancel();
if (_lastCompleter != null && !_lastCompleter!.isCompleted) { if (_lastCompleter != null && !_lastCompleter!.isCompleted) {
_lastCompleter! _lastCompleter!.completeError(StateError("Cancelled by new search"));
.completeError(StateError("Cancelled by new search"));
} }
final completer = Completer<PaginatedBookableSpaces>(); final completer = Completer<PaginatedBookableSpaces>();

View File

@ -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<PaginatedBookableSpaces> getBookableSpaces({
required LoadBookableSpacesParam param,
});
}

View File

@ -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<PaginatedBookableSpaces> getBookableSpaces({
required LoadCommunitiesParam param,
});
}

View File

@ -1,12 +1,12 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_bloc/flutter_bloc.dart'; 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_event.dart';
import 'package:syncrow_web/pages/access_management/booking_system/presentation/bloc/sidebar/sidebar_state.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<SidebarEvent, SidebarState> { class SidebarBloc extends Bloc<SidebarEvent, SidebarState> {
final BookingSystemService _bookingService; final BookableSystemService _bookingService;
int _currentPage = 1; int _currentPage = 1;
final int _pageSize = 20; final int _pageSize = 20;
String _currentSearch = ''; String _currentSearch = '';
@ -35,7 +35,7 @@ class SidebarBloc extends Bloc<SidebarEvent, SidebarState> {
_currentSearch = ''; _currentSearch = '';
final paginatedSpaces = await _bookingService.getBookableSpaces( final paginatedSpaces = await _bookingService.getBookableSpaces(
param: LoadCommunitiesParam( param: LoadBookableSpacesParam(
page: _currentPage, page: _currentPage,
size: _pageSize, size: _pageSize,
search: _currentSearch, search: _currentSearch,
@ -69,11 +69,10 @@ class SidebarBloc extends Bloc<SidebarEvent, SidebarState> {
_currentPage++; _currentPage++;
final paginatedSpaces = await _bookingService.getBookableSpaces( final paginatedSpaces = await _bookingService.getBookableSpaces(
param: LoadCommunitiesParam( param: LoadBookableSpacesParam(
page: _currentPage, page: _currentPage,
size: _pageSize, size: _pageSize,
search: _currentSearch, search: _currentSearch,
// Add any other required params
), ),
); );
@ -105,11 +104,10 @@ class SidebarBloc extends Bloc<SidebarEvent, SidebarState> {
_currentPage = 1; _currentPage = 1;
emit(state.copyWith(isLoading: true, errorMessage: null)); emit(state.copyWith(isLoading: true, errorMessage: null));
final paginatedSpaces = await _bookingService.getBookableSpaces( final paginatedSpaces = await _bookingService.getBookableSpaces(
param: LoadCommunitiesParam( param: LoadBookableSpacesParam(
page: _currentPage, page: _currentPage,
size: _pageSize, size: _pageSize,
search: _currentSearch, search: _currentSearch,
// Add other fields if required
), ),
); );
emit(state.copyWith( emit(state.copyWith(

View File

@ -2,7 +2,7 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.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/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_bloc.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_event.dart';
@ -23,7 +23,7 @@ class BookingSidebar extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider( return BlocProvider(
create: (context) => SidebarBloc(BookableSpacesService( create: (context) => SidebarBloc(RemoteBookableSpacesService(
HTTPService(), HTTPService(),
)) ))
..add(LoadBookableSpaces()), ..add(LoadBookableSpaces()),