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:
Faris Armoush
2025-07-06 12:39:54 +03:00
parent fdea4b1cd0
commit 826dea8054

View File

@ -1,4 +1,5 @@
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/update_community/domain/services/update_community_service.dart';
import 'package:syncrow_web/services/api/api_exception.dart';
@ -13,14 +14,14 @@ class RemoteUpdateCommunityService implements UpdateCommunityService {
@override
Future<CommunityModel> updateCommunity(CommunityModel param) async {
final endpoint = await _makeUrl(param.uuid);
try {
final response = await _httpService.put(
path: 'endpoint',
expectedResponseModel: (data) => CommunityModel.fromJson(
data as Map<String, dynamic>,
),
await _httpService.put(
path: endpoint,
body: {'name': param.name},
expectedResponseModel: (data) => null,
);
return response;
return param;
} on DioException catch (e) {
final message = e.response?.data as Map<String, dynamic>?;
final error = message?['error'] as Map<String, dynamic>?;
@ -35,4 +36,12 @@ class RemoteUpdateCommunityService implements UpdateCommunityService {
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';
}
}