fixed get communities

This commit is contained in:
hannathkadher
2024-10-02 11:13:25 +04:00
parent 8672817791
commit 5d397691b6

View File

@ -11,13 +11,19 @@ class CommunitySpaceManagementApi {
try { try {
final response = await HTTPService().get( final response = await HTTPService().get(
path: ApiEndpoints.getCommunityList, path: ApiEndpoints.getCommunityList,
showServerMessage: true,
expectedResponseModel: (json) { expectedResponseModel: (json) {
List<dynamic> jsonData = json; // Access the 'data' key from the response
List<dynamic> jsonData = json['data'];
// Check if jsonData is actually a List
if (jsonData is List) {
List<CommunityModel> communityList = jsonData.map((jsonItem) { List<CommunityModel> communityList = jsonData.map((jsonItem) {
return CommunityModel.fromJson(jsonItem); return CommunityModel.fromJson(jsonItem);
}).toList(); }).toList();
return communityList; return communityList;
} else {
throw Exception('Expected a list but got something else.');
}
}, },
); );
return response; return response;
@ -32,7 +38,6 @@ class CommunitySpaceManagementApi {
final response = await HTTPService().get( final response = await HTTPService().get(
path: ApiEndpoints.getCommunityById path: ApiEndpoints.getCommunityById
.replaceAll('{communityId}', communityId), .replaceAll('{communityId}', communityId),
showServerMessage: true,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return CommunityModel.fromJson(json['data']); return CommunityModel.fromJson(json['data']);
}, },
@ -54,7 +59,6 @@ class CommunitySpaceManagementApi {
'description': description, 'description': description,
'regionId': regionId, 'regionId': regionId,
}, },
showServerMessage: true,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return CommunityModel.fromJson(json['data']); return CommunityModel.fromJson(json['data']);
}, },
@ -73,7 +77,6 @@ class CommunitySpaceManagementApi {
path: ApiEndpoints.updateCommunity path: ApiEndpoints.updateCommunity
.replaceAll('{communityId}', communityId), .replaceAll('{communityId}', communityId),
body: community.toMap(), body: community.toMap(),
showServerMessage: true,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return json['success'] ?? false; return json['success'] ?? false;
}, },
@ -90,7 +93,6 @@ class CommunitySpaceManagementApi {
final response = await HTTPService().delete( final response = await HTTPService().delete(
path: ApiEndpoints.deleteCommunity path: ApiEndpoints.deleteCommunity
.replaceAll('{communityId}', communityId), .replaceAll('{communityId}', communityId),
showServerMessage: true,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return json['success'] ?? false; return json['success'] ?? false;
}, },
@ -106,7 +108,6 @@ class CommunitySpaceManagementApi {
try { try {
final response = await HTTPService().get( final response = await HTTPService().get(
path: ApiEndpoints.listSpaces.replaceAll('{communityId}', communityId), path: ApiEndpoints.listSpaces.replaceAll('{communityId}', communityId),
showServerMessage: true,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return SpacesResponse.fromJson(json); return SpacesResponse.fromJson(json);
}, },
@ -127,13 +128,12 @@ class CommunitySpaceManagementApi {
} }
} }
Future<SpaceModel> getSpace(String communityId, String spaceId) async { Future<SpaceModel?> getSpace(String communityId, String spaceId) async {
try { try {
final response = await HTTPService().get( final response = await HTTPService().get(
path: ApiEndpoints.getSpace path: ApiEndpoints.getSpace
.replaceAll('{communityId}', communityId) .replaceAll('{communityId}', communityId)
.replaceAll('{spaceId}', spaceId), .replaceAll('{spaceId}', spaceId),
showServerMessage: true,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return SpaceModel.fromJson(json); return SpaceModel.fromJson(json);
}, },
@ -141,7 +141,7 @@ class CommunitySpaceManagementApi {
return response; return response;
} catch (e) { } catch (e) {
debugPrint('Error fetching space: $e'); debugPrint('Error fetching space: $e');
return SpaceModel(); // Assuming an empty SpaceModel constructor return null; // Assuming an empty SpaceModel constructor
} }
} }
@ -159,7 +159,6 @@ class CommunitySpaceManagementApi {
final response = await HTTPService().post( final response = await HTTPService().post(
path: ApiEndpoints.createSpace.replaceAll('{communityId}', communityId), path: ApiEndpoints.createSpace.replaceAll('{communityId}', communityId),
body: body, body: body,
showServerMessage: true,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return SpaceModel.fromJson(json['data']); return SpaceModel.fromJson(json['data']);
}, },
@ -179,7 +178,6 @@ class CommunitySpaceManagementApi {
.replaceAll('{communityId}', communityId) .replaceAll('{communityId}', communityId)
.replaceAll('{spaceId}', spaceId), .replaceAll('{spaceId}', spaceId),
body: space.toMap(), body: space.toMap(),
showServerMessage: true,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return json['success'] ?? false; return json['success'] ?? false;
}, },
@ -197,7 +195,6 @@ class CommunitySpaceManagementApi {
path: ApiEndpoints.deleteSpace path: ApiEndpoints.deleteSpace
.replaceAll('{communityId}', communityId) .replaceAll('{communityId}', communityId)
.replaceAll('{spaceId}', spaceId), .replaceAll('{spaceId}', spaceId),
showServerMessage: true,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return json['success'] ?? false; return json['success'] ?? false;
}, },
@ -214,7 +211,6 @@ class CommunitySpaceManagementApi {
final response = await HTTPService().get( final response = await HTTPService().get(
path: ApiEndpoints.getSpaceHierarchy path: ApiEndpoints.getSpaceHierarchy
.replaceAll('{communityId}', communityId), .replaceAll('{communityId}', communityId),
showServerMessage: true,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return (json['data'] as List) return (json['data'] as List)
.map((spaceJson) => SpaceModel.fromJson(spaceJson)) .map((spaceJson) => SpaceModel.fromJson(spaceJson))