mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
Implement community update endpoint: Refactor RemoteUpdateCommunityService
to dynamically construct the update URL using the project UUID. This change enhances the service's flexibility and error handling by ensuring the correct endpoint is used for community updates.
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
import 'package:dio/dio.dart';
|
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/community_model.dart';
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/update_community/domain/services/update_community_service.dart';
|
import 'package:syncrow_web/pages/space_management_v2/modules/update_community/domain/services/update_community_service.dart';
|
||||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
import 'package:syncrow_web/services/api/api_exception.dart';
|
||||||
@ -13,14 +14,14 @@ class RemoteUpdateCommunityService implements UpdateCommunityService {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<CommunityModel> updateCommunity(CommunityModel param) async {
|
Future<CommunityModel> updateCommunity(CommunityModel param) async {
|
||||||
|
final endpoint = await _makeUrl(param.uuid);
|
||||||
try {
|
try {
|
||||||
final response = await _httpService.put(
|
await _httpService.put(
|
||||||
path: 'endpoint',
|
path: endpoint,
|
||||||
expectedResponseModel: (data) => CommunityModel.fromJson(
|
body: {'name': param.name},
|
||||||
data as Map<String, dynamic>,
|
expectedResponseModel: (data) => null,
|
||||||
),
|
|
||||||
);
|
);
|
||||||
return response;
|
return param;
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final message = e.response?.data as Map<String, dynamic>?;
|
final message = e.response?.data as Map<String, dynamic>?;
|
||||||
final error = message?['error'] as Map<String, dynamic>?;
|
final error = message?['error'] as Map<String, dynamic>?;
|
||||||
@ -35,4 +36,12 @@ class RemoteUpdateCommunityService implements UpdateCommunityService {
|
|||||||
throw APIException(formattedErrorMessage);
|
throw APIException(formattedErrorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<String> _makeUrl(String communityUuid) async {
|
||||||
|
final projectUuid = await ProjectManager.getProjectUUID();
|
||||||
|
if (projectUuid == null) {
|
||||||
|
throw APIException('Project UUID is not set');
|
||||||
|
}
|
||||||
|
return '/projects/$projectUuid/communities/$communityUuid';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user