diff --git a/lib/services/space_mana_api.dart b/lib/services/space_mana_api.dart index 0a96ed2b..bdb369d7 100644 --- a/lib/services/space_mana_api.dart +++ b/lib/services/space_mana_api.dart @@ -11,13 +11,19 @@ class CommunitySpaceManagementApi { try { final response = await HTTPService().get( path: ApiEndpoints.getCommunityList, - showServerMessage: true, expectedResponseModel: (json) { - List jsonData = json; - List communityList = jsonData.map((jsonItem) { - return CommunityModel.fromJson(jsonItem); - }).toList(); - return communityList; + // Access the 'data' key from the response + List jsonData = json['data']; + + // Check if jsonData is actually a List + if (jsonData is List) { + List 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 getSpace(String communityId, String spaceId) async { + Future 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))