mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-25 17:09:40 +00:00
Implement ReorderSpacesService.
This commit is contained in:
@ -0,0 +1,35 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/reorder_spaces/domain/params/reorder_spaces_param.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/reorder_spaces/domain/services/reorder_spaces_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 RemoteReorderSpacesService implements ReorderSpacesService {
|
||||||
|
RemoteReorderSpacesService(this._httpClient);
|
||||||
|
|
||||||
|
final HTTPService _httpClient;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> reorderSpaces(ReorderSpacesParam param) async {
|
||||||
|
try {
|
||||||
|
await _httpClient.post(
|
||||||
|
path: ApiEndpoints.reorderSpaces,
|
||||||
|
body: param,
|
||||||
|
expectedResponseModel: (json) => json,
|
||||||
|
);
|
||||||
|
} on DioException catch (e) {
|
||||||
|
final message = e.response?.data as Map<String, dynamic>?;
|
||||||
|
throw APIException(_getErrorMessageFromBody(message));
|
||||||
|
} catch (e) {
|
||||||
|
throw APIException(e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String _getErrorMessageFromBody(Map<String, dynamic>? body) {
|
||||||
|
if (body == null) return 'Failed to delete space';
|
||||||
|
final error = body['error'] as Map<String, dynamic>?;
|
||||||
|
final errorMessage = error?['message'] as String? ?? '';
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user