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 {
final response = await HTTPService().get(
path: ApiEndpoints.getCommunityList,
showServerMessage: true,
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) {
return CommunityModel.fromJson(jsonItem);
}).toList();
return communityList;
} else {
throw Exception('Expected a list but got something else.');
}
},
);
return response;
@ -32,7 +38,6 @@ class CommunitySpaceManagementApi {
final response = await HTTPService().get(
path: ApiEndpoints.getCommunityById
.replaceAll('{communityId}', communityId),
showServerMessage: true,
expectedResponseModel: (json) {
return CommunityModel.fromJson(json['data']);
},
@ -54,7 +59,6 @@ class CommunitySpaceManagementApi {
'description': description,
'regionId': regionId,
},
showServerMessage: true,
expectedResponseModel: (json) {
return CommunityModel.fromJson(json['data']);
},
@ -73,7 +77,6 @@ class CommunitySpaceManagementApi {
path: ApiEndpoints.updateCommunity
.replaceAll('{communityId}', communityId),
body: community.toMap(),
showServerMessage: true,
expectedResponseModel: (json) {
return json['success'] ?? false;
},
@ -90,7 +93,6 @@ class CommunitySpaceManagementApi {
final response = await HTTPService().delete(
path: ApiEndpoints.deleteCommunity
.replaceAll('{communityId}', communityId),
showServerMessage: true,
expectedResponseModel: (json) {
return json['success'] ?? false;
},
@ -106,7 +108,6 @@ class CommunitySpaceManagementApi {
try {
final response = await HTTPService().get(
path: ApiEndpoints.listSpaces.replaceAll('{communityId}', communityId),
showServerMessage: true,
expectedResponseModel: (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 {
final response = await HTTPService().get(
path: ApiEndpoints.getSpace
.replaceAll('{communityId}', communityId)
.replaceAll('{spaceId}', spaceId),
showServerMessage: true,
expectedResponseModel: (json) {
return SpaceModel.fromJson(json);
},
@ -141,7 +141,7 @@ class CommunitySpaceManagementApi {
return response;
} catch (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(
path: ApiEndpoints.createSpace.replaceAll('{communityId}', communityId),
body: body,
showServerMessage: true,
expectedResponseModel: (json) {
return SpaceModel.fromJson(json['data']);
},
@ -179,7 +178,6 @@ class CommunitySpaceManagementApi {
.replaceAll('{communityId}', communityId)
.replaceAll('{spaceId}', spaceId),
body: space.toMap(),
showServerMessage: true,
expectedResponseModel: (json) {
return json['success'] ?? false;
},
@ -197,7 +195,6 @@ class CommunitySpaceManagementApi {
path: ApiEndpoints.deleteSpace
.replaceAll('{communityId}', communityId)
.replaceAll('{spaceId}', spaceId),
showServerMessage: true,
expectedResponseModel: (json) {
return json['success'] ?? false;
},
@ -214,7 +211,6 @@ class CommunitySpaceManagementApi {
final response = await HTTPService().get(
path: ApiEndpoints.getSpaceHierarchy
.replaceAll('{communityId}', communityId),
showServerMessage: true,
expectedResponseModel: (json) {
return (json['data'] as List)
.map((spaceJson) => SpaceModel.fromJson(spaceJson))