mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-25 18:09:41 +00:00
update spaces remote files
This commit is contained in:
@ -0,0 +1,40 @@
|
|||||||
|
import 'package:dio/dio.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/update_bookable_space_param.dart';
|
||||||
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/service/update_bookable_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';
|
||||||
|
|
||||||
|
class RemoteUpdateBookableSpaceService implements UpdateBookableSpaceService {
|
||||||
|
final HTTPService _httpService;
|
||||||
|
RemoteUpdateBookableSpaceService(this._httpService);
|
||||||
|
static const _defaultErrorMessage = 'Failed to load Bookable Spaces';
|
||||||
|
@override
|
||||||
|
Future<BookableSpaceConfig> update(
|
||||||
|
UpdateBookableSpaceParam updateParam) async {
|
||||||
|
try {
|
||||||
|
final response = await _httpService.put(
|
||||||
|
path: '${ApiEndpoints.bookableSpaces}/${updateParam.spaceUuid}',
|
||||||
|
body: updateParam.toJson(),
|
||||||
|
expectedResponseModel: (json) {
|
||||||
|
return BookableSpaceConfig.fromJson(
|
||||||
|
json['data'] as Map<String, dynamic>);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user