Refactor booking system: replace individual parameters with LoadBookableSpacesParam for improved clarity and maintainability

This commit is contained in:
mohammad
2025-07-10 10:56:10 +03:00
parent 2d16bda61d
commit 3e95bf4473
6 changed files with 244 additions and 199 deletions

View File

@ -3,10 +3,10 @@ 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/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<SidebarEvent, SidebarState> {
final BookingSystemService _bookingService;
Timer? _searchDebounce;
int _currentPage = 1;
final int _pageSize = 20;
String _currentSearch = '';
@ -35,9 +35,11 @@ class SidebarBloc extends Bloc<SidebarEvent, SidebarState> {
_currentSearch = '';
final paginatedSpaces = await _bookingService.getBookableSpaces(
page: _currentPage,
size: _pageSize,
search: _currentSearch,
param: LoadCommunitiesParam(
page: _currentPage,
size: _pageSize,
search: _currentSearch,
),
);
emit(state.copyWith(
@ -67,9 +69,12 @@ class SidebarBloc extends Bloc<SidebarEvent, SidebarState> {
_currentPage++;
final paginatedSpaces = await _bookingService.getBookableSpaces(
page: _currentPage,
size: _pageSize,
search: _currentSearch,
param: LoadCommunitiesParam(
page: _currentPage,
size: _pageSize,
search: _currentSearch,
// Add any other required params
),
);
final updatedRooms = [...state.allRooms, ...paginatedSpaces.data];
@ -79,6 +84,7 @@ class SidebarBloc extends Bloc<SidebarEvent, SidebarState> {
displayedRooms: updatedRooms,
isLoadingMore: false,
hasMore: paginatedSpaces.hasNext,
totalPages: paginatedSpaces.totalPage,
currentPage: _currentPage,
));
} catch (e) {
@ -99,11 +105,13 @@ class SidebarBloc extends Bloc<SidebarEvent, SidebarState> {
_currentPage = 1;
emit(state.copyWith(isLoading: true, errorMessage: null));
final paginatedSpaces = await _bookingService.getBookableSpaces(
page: _currentPage,
size: _pageSize,
search: _currentSearch,
param: LoadCommunitiesParam(
page: _currentPage,
size: _pageSize,
search: _currentSearch,
// Add other fields if required
),
);
emit(state.copyWith(
allRooms: paginatedSpaces.data,
displayedRooms: paginatedSpaces.data,
@ -137,7 +145,6 @@ class SidebarBloc extends Bloc<SidebarEvent, SidebarState> {
@override
Future<void> close() {
_searchDebounce?.cancel();
return super.close();
}
}