mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
build services for them
This commit is contained in:
@ -0,0 +1,60 @@
|
|||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/models/bookable_space_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/models/bookable_space_config.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/params/bookable_spaces_params.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/service/bookable_spaces_service.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/shared/models/paginated_data_model.dart';
|
||||||
|
|
||||||
|
class DummyBookableSpacesService implements BookableSpacesService {
|
||||||
|
@override
|
||||||
|
Future<PaginatedDataModel<BookableSpacemodel>> load(
|
||||||
|
BookableSpacesParams param) async {
|
||||||
|
return PaginatedDataModel(
|
||||||
|
data: [
|
||||||
|
BookableSpacemodel(
|
||||||
|
spaceName: 'space1',
|
||||||
|
spaceConfig: BookableSpaceConfig(
|
||||||
|
configUuid: 'uuid',
|
||||||
|
bookableDays: ['wed', 'saturday'],
|
||||||
|
availability: true,
|
||||||
|
bookingEndTime: '08:00 PM',
|
||||||
|
bookingStartTime: '5:00 PM',
|
||||||
|
cost: 6,
|
||||||
|
),
|
||||||
|
spaceUuid: 'uuiiddd',
|
||||||
|
spaceVirtualAddress: 'idvirtual1',
|
||||||
|
),
|
||||||
|
BookableSpacemodel(
|
||||||
|
spaceName: 'space2',
|
||||||
|
spaceConfig: BookableSpaceConfig(
|
||||||
|
configUuid: 'uuid',
|
||||||
|
bookableDays: ['wed', 'thur'],
|
||||||
|
availability: true,
|
||||||
|
bookingEndTime: '08:00 PM',
|
||||||
|
bookingStartTime: '5:00 PM',
|
||||||
|
cost: 6,
|
||||||
|
),
|
||||||
|
spaceUuid: 'uuiiddd',
|
||||||
|
spaceVirtualAddress: 'idvirtual1',
|
||||||
|
),
|
||||||
|
BookableSpacemodel(
|
||||||
|
spaceName: 'space3',
|
||||||
|
spaceConfig: BookableSpaceConfig(
|
||||||
|
configUuid: 'uuid',
|
||||||
|
bookableDays: ['wed', 'fri', 'tues'],
|
||||||
|
availability: true,
|
||||||
|
bookingEndTime: '08:00 PM',
|
||||||
|
bookingStartTime: '5:00 PM',
|
||||||
|
cost: 6,
|
||||||
|
),
|
||||||
|
spaceUuid: 'uuiiddd',
|
||||||
|
spaceVirtualAddress: 'idvirtual1',
|
||||||
|
)
|
||||||
|
],
|
||||||
|
page: 1,
|
||||||
|
size: 1,
|
||||||
|
hasNext: false,
|
||||||
|
totalItems: 3,
|
||||||
|
totalPages: 1,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/models/bookable_space_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/models/bookable_space_config.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/params/non_bookable_spaces_params.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/service/non_bookable_spaces_service.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/service/send_bookable_spaces_to_api_params.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/shared/models/paginated_data_model.dart';
|
||||||
|
|
||||||
|
class DummyNonNookableSpaces implements NonBookableSpacesService {
|
||||||
|
@override
|
||||||
|
Future<PaginatedDataModel<BookableSpacemodel>> load(
|
||||||
|
NonBookableSpacesParams params) {
|
||||||
|
return Future.value(PaginatedDataModel<BookableSpacemodel>(
|
||||||
|
data: [
|
||||||
|
BookableSpacemodel(
|
||||||
|
spaceName: 'space3',
|
||||||
|
spaceConfig: BookableSpaceConfig(
|
||||||
|
configUuid: 'uuid',
|
||||||
|
bookableDays: ['wed', 'saturday'],
|
||||||
|
availability: true,
|
||||||
|
bookingEndTime: '08:00 PM',
|
||||||
|
bookingStartTime: '5:00 PM',
|
||||||
|
cost: 6,
|
||||||
|
),
|
||||||
|
spaceUuid: 'uuiiddd',
|
||||||
|
spaceVirtualAddress: 'idvirtual1',
|
||||||
|
),
|
||||||
|
BookableSpacemodel(
|
||||||
|
spaceName: 'space3',
|
||||||
|
spaceConfig: BookableSpaceConfig(
|
||||||
|
configUuid: 'uuid',
|
||||||
|
bookableDays: ['wed', 'saturday', 'thuresday'],
|
||||||
|
availability: true,
|
||||||
|
bookingEndTime: '08:00 PM',
|
||||||
|
bookingStartTime: '5:00 PM',
|
||||||
|
cost: 5,
|
||||||
|
),
|
||||||
|
spaceUuid: 'uuiiddd',
|
||||||
|
spaceVirtualAddress: 'idvirtual2',
|
||||||
|
),
|
||||||
|
BookableSpacemodel(
|
||||||
|
spaceName: 'space3',
|
||||||
|
spaceConfig: BookableSpaceConfig(
|
||||||
|
configUuid: 'uuid',
|
||||||
|
bookableDays: [
|
||||||
|
'saturday',
|
||||||
|
'sunday',
|
||||||
|
'Monday',
|
||||||
|
'tuesday',
|
||||||
|
'wed',
|
||||||
|
'thuresday'
|
||||||
|
],
|
||||||
|
availability: true,
|
||||||
|
bookingEndTime: '08:00 PM',
|
||||||
|
bookingStartTime: '5:00 PM',
|
||||||
|
cost: 2,
|
||||||
|
),
|
||||||
|
spaceUuid: 'uuiiddd',
|
||||||
|
spaceVirtualAddress: 'idvirtual3',
|
||||||
|
)
|
||||||
|
],
|
||||||
|
page: 1,
|
||||||
|
size: 1,
|
||||||
|
hasNext: false,
|
||||||
|
totalPages: 0,
|
||||||
|
totalItems: 0,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> sendBookableSpacesToApi(
|
||||||
|
SendBookableSpacesToApiParams params) async {}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/models/bookable_space_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/params/bookable_spaces_params.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/service/bookable_spaces_service.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/shared/models/paginated_data_model.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 RemoteBookableSpacesService implements BookableSpacesService {
|
||||||
|
final HTTPService _httpService;
|
||||||
|
RemoteBookableSpacesService(this._httpService);
|
||||||
|
static const _defaultErrorMessage = 'Failed to load tags';
|
||||||
|
@override
|
||||||
|
Future<PaginatedDataModel<BookableSpacemodel>> load(
|
||||||
|
BookableSpacesParams param) async {
|
||||||
|
try {
|
||||||
|
final response = await _httpService.get(
|
||||||
|
//TODO: you have to Chage this API call Path
|
||||||
|
path: ApiEndpoints.listTags,
|
||||||
|
//*************|********** */
|
||||||
|
expectedResponseModel: (json) {
|
||||||
|
final result = json as Map<String, dynamic>;
|
||||||
|
return PaginatedDataModel.fromJson(
|
||||||
|
result,
|
||||||
|
BookableSpacemodel.fromJsonList,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} on DioException catch (e) {
|
||||||
|
final message = e.response?.data as Map<String, dynamic>?;
|
||||||
|
final error = message?['error'] as Map<String, dynamic>?;
|
||||||
|
final errorMessage = error?['error'] as String? ?? '';
|
||||||
|
final formattedErrorMessage = [
|
||||||
|
_defaultErrorMessage,
|
||||||
|
errorMessage,
|
||||||
|
].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
} catch (e) {
|
||||||
|
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/models/bookable_space_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/params/non_bookable_spaces_params.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/service/non_bookable_spaces_service.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/service/send_bookable_spaces_to_api_params.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/shared/models/paginated_data_model.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 RemoteNonBookableSpaces implements NonBookableSpacesService {
|
||||||
|
final HTTPService _httpService;
|
||||||
|
RemoteNonBookableSpaces(this._httpService);
|
||||||
|
static const _defaultErrorMessage = 'Failed to load Spaces';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<PaginatedDataModel<BookableSpacemodel>> load(
|
||||||
|
NonBookableSpacesParams params) async {
|
||||||
|
try {
|
||||||
|
final response = await _httpService.get(
|
||||||
|
//TODO: you have to Chage this API call Path
|
||||||
|
path: ApiEndpoints.listTags,
|
||||||
|
//*************|********** */
|
||||||
|
expectedResponseModel: (json) {
|
||||||
|
final result = json as Map<String, dynamic>;
|
||||||
|
return PaginatedDataModel.fromJson(
|
||||||
|
result,
|
||||||
|
BookableSpacemodel.fromJsonList,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} on DioException catch (e) {
|
||||||
|
final message = e.response?.data as Map<String, dynamic>?;
|
||||||
|
final error = message?['error'] as Map<String, dynamic>?;
|
||||||
|
final errorMessage = error?['error'] as String? ?? '';
|
||||||
|
final formattedErrorMessage = [
|
||||||
|
_defaultErrorMessage,
|
||||||
|
errorMessage,
|
||||||
|
].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
} catch (e) {
|
||||||
|
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> sendBookableSpacesToApi(
|
||||||
|
SendBookableSpacesToApiParams params) async {
|
||||||
|
try {
|
||||||
|
await _httpService.post(
|
||||||
|
path: ApiEndpoints.addBookableSpaces,
|
||||||
|
body: params.toJson(),
|
||||||
|
expectedResponseModel: (p0) {},
|
||||||
|
);
|
||||||
|
} on DioException catch (e) {
|
||||||
|
final message = e.response?.data as Map<String, dynamic>?;
|
||||||
|
final error = message?['error'] as Map<String, dynamic>?;
|
||||||
|
final errorMessage = error?['error'] as String? ?? '';
|
||||||
|
final formattedErrorMessage = [
|
||||||
|
_defaultErrorMessage,
|
||||||
|
errorMessage,
|
||||||
|
].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
} catch (e) {
|
||||||
|
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/models/bookable_space_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/params/bookable_spaces_params.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/shared/models/paginated_data_model.dart';
|
||||||
|
|
||||||
|
abstract class BookableSpacesService {
|
||||||
|
Future<PaginatedDataModel<BookableSpacemodel>> load(
|
||||||
|
BookableSpacesParams param);
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/models/bookable_space_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/params/non_bookable_spaces_params.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/service/send_bookable_spaces_to_api_params.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/main_module/shared/models/paginated_data_model.dart';
|
||||||
|
|
||||||
|
abstract class NonBookableSpacesService {
|
||||||
|
Future<PaginatedDataModel<BookableSpacemodel>> load(
|
||||||
|
NonBookableSpacesParams params);
|
||||||
|
Future<void> sendBookableSpacesToApi(SendBookableSpacesToApiParams params);
|
||||||
|
}
|
Reference in New Issue
Block a user