mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-24 22:32:28 +00:00
Implemented duplicate_space
data layer.
This commit is contained in:
@ -0,0 +1,58 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/space_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/duplicate_space/domain/params/duplicate_space_param.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/duplicate_space/domain/services/duplicate_space_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';
|
||||||
|
|
||||||
|
final class RemoteDuplicateSpaceService implements DuplicateSpaceService {
|
||||||
|
RemoteDuplicateSpaceService(this._httpService);
|
||||||
|
|
||||||
|
final HTTPService _httpService;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<SpaceModel> duplicateSpace(DuplicateSpaceParam param) async {
|
||||||
|
try {
|
||||||
|
final response = await _httpService.post(
|
||||||
|
path: await _makeUrl(param),
|
||||||
|
body: param.toJson(),
|
||||||
|
expectedResponseModel: (json) {
|
||||||
|
final response = json as Map<String, dynamic>;
|
||||||
|
final data = response['data'] as Map<String, dynamic>;
|
||||||
|
return SpaceModel.fromJson(data);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
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? ?? '';
|
||||||
|
throw APIException(errorMessage);
|
||||||
|
} catch (e) {
|
||||||
|
throw APIException(e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<String> _makeUrl(DuplicateSpaceParam param) async {
|
||||||
|
final projectUuid = await ProjectManager.getProjectUUID();
|
||||||
|
if (projectUuid == null) {
|
||||||
|
throw APIException('Project UUID is not set');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param.communityUuid.isEmpty) {
|
||||||
|
throw APIException('Community UUID is not set');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param.spaceUuid.isEmpty) {
|
||||||
|
throw APIException('Space UUID is not set');
|
||||||
|
}
|
||||||
|
|
||||||
|
return ApiEndpoints.duplicateSpace
|
||||||
|
..replaceAll('{projectUuid}', projectUuid)
|
||||||
|
..replaceAll('{communityUuid}', param.communityUuid)
|
||||||
|
..replaceAll('{spaceUuid}', param.spaceUuid);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user