mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
fixed issue of not recursively calling communtiy list
This commit is contained in:
@ -8,22 +8,31 @@ import 'package:syncrow_web/utils/constants/api_const.dart';
|
|||||||
|
|
||||||
class CommunitySpaceManagementApi {
|
class CommunitySpaceManagementApi {
|
||||||
// Community Management APIs
|
// Community Management APIs
|
||||||
Future<List<CommunityModel>> fetchCommunities() async {
|
Future<List<CommunityModel>> fetchCommunities({int page = 1}) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().get(
|
List<CommunityModel> allCommunities = [];
|
||||||
path: ApiEndpoints.getCommunityList,
|
bool hasNext = true;
|
||||||
expectedResponseModel: (json) {
|
|
||||||
// Access the 'data' key from the response
|
|
||||||
List<dynamic> jsonData = json['data'];
|
|
||||||
|
|
||||||
// Check if jsonData is actually a List
|
while (hasNext) {
|
||||||
List<CommunityModel> communityList = jsonData.map((jsonItem) {
|
await HTTPService().get(
|
||||||
return CommunityModel.fromJson(jsonItem);
|
path: ApiEndpoints.getCommunityList,
|
||||||
}).toList();
|
queryParameters: {'page': page},
|
||||||
return communityList;
|
expectedResponseModel: (json) {
|
||||||
},
|
List<dynamic> jsonData = json['data'];
|
||||||
);
|
hasNext = json['hasNext'] ?? false;
|
||||||
return response;
|
int currentPage = json['page'] ?? 1;
|
||||||
|
List<CommunityModel> communityList = jsonData.map((jsonItem) {
|
||||||
|
return CommunityModel.fromJson(jsonItem);
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
allCommunities.addAll(communityList);
|
||||||
|
page = currentPage + 1;
|
||||||
|
return communityList;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return allCommunities;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('Error fetching communities: $e');
|
debugPrint('Error fetching communities: $e');
|
||||||
return [];
|
return [];
|
||||||
@ -33,7 +42,8 @@ class CommunitySpaceManagementApi {
|
|||||||
Future<CommunityModel?> getCommunityById(String communityId) async {
|
Future<CommunityModel?> getCommunityById(String communityId) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().get(
|
final response = await HTTPService().get(
|
||||||
path: ApiEndpoints.getCommunityById.replaceAll('{communityId}', communityId),
|
path: ApiEndpoints.getCommunityById
|
||||||
|
.replaceAll('{communityId}', communityId),
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return CommunityModel.fromJson(json['data']);
|
return CommunityModel.fromJson(json['data']);
|
||||||
},
|
},
|
||||||
@ -45,7 +55,8 @@ class CommunitySpaceManagementApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<CommunityModel?> createCommunity(String name, String description) async {
|
Future<CommunityModel?> createCommunity(
|
||||||
|
String name, String description) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().post(
|
final response = await HTTPService().post(
|
||||||
path: ApiEndpoints.createCommunity,
|
path: ApiEndpoints.createCommunity,
|
||||||
@ -67,7 +78,8 @@ class CommunitySpaceManagementApi {
|
|||||||
Future<bool> updateCommunity(String communityId, String name) async {
|
Future<bool> updateCommunity(String communityId, String name) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().put(
|
final response = await HTTPService().put(
|
||||||
path: ApiEndpoints.updateCommunity.replaceAll('{communityId}', communityId),
|
path: ApiEndpoints.updateCommunity
|
||||||
|
.replaceAll('{communityId}', communityId),
|
||||||
body: {
|
body: {
|
||||||
'name': name,
|
'name': name,
|
||||||
},
|
},
|
||||||
@ -85,7 +97,8 @@ class CommunitySpaceManagementApi {
|
|||||||
Future<bool> deleteCommunity(String communityId) async {
|
Future<bool> deleteCommunity(String communityId) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().delete(
|
final response = await HTTPService().delete(
|
||||||
path: ApiEndpoints.deleteCommunity.replaceAll('{communityId}', communityId),
|
path: ApiEndpoints.deleteCommunity
|
||||||
|
.replaceAll('{communityId}', communityId),
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return json['success'] ?? false;
|
return json['success'] ?? false;
|
||||||
},
|
},
|
||||||
@ -236,10 +249,12 @@ class CommunitySpaceManagementApi {
|
|||||||
Future<List<SpaceModel>> getSpaceHierarchy(String communityId) async {
|
Future<List<SpaceModel>> getSpaceHierarchy(String communityId) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().get(
|
final response = await HTTPService().get(
|
||||||
path: ApiEndpoints.getSpaceHierarchy.replaceAll('{communityId}', communityId),
|
path: ApiEndpoints.getSpaceHierarchy
|
||||||
|
.replaceAll('{communityId}', communityId),
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
final spaceModels =
|
final spaceModels = (json['data'] as List)
|
||||||
(json['data'] as List).map((spaceJson) => SpaceModel.fromJson(spaceJson)).toList();
|
.map((spaceJson) => SpaceModel.fromJson(spaceJson))
|
||||||
|
.toList();
|
||||||
|
|
||||||
return spaceModels;
|
return spaceModels;
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user