mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
Added pagination and search logic in space tree
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/pages/space_tree/model/pagination_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/create_subspace_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||
@ -11,8 +12,7 @@ import 'package:syncrow_web/utils/constants/api_const.dart';
|
||||
|
||||
class CommunitySpaceManagementApi {
|
||||
// Community Management APIs
|
||||
Future<List<CommunityModel>> fetchCommunities(String projectId,
|
||||
{int page = 1, bool includeSpaces = false}) async {
|
||||
Future<List<CommunityModel>> fetchCommunities(String projectId, {int page = 1}) async {
|
||||
try {
|
||||
List<CommunityModel> allCommunities = [];
|
||||
bool hasNext = true;
|
||||
@ -20,7 +20,9 @@ class CommunitySpaceManagementApi {
|
||||
while (hasNext) {
|
||||
await HTTPService().get(
|
||||
path: ApiEndpoints.getCommunityList.replaceAll('{projectId}', projectId),
|
||||
queryParameters: {'page': page, 'includeSpaces': includeSpaces},
|
||||
queryParameters: {
|
||||
'page': page,
|
||||
},
|
||||
expectedResponseModel: (json) {
|
||||
try {
|
||||
List<dynamic> jsonData = json['data'] ?? [];
|
||||
@ -46,6 +48,38 @@ class CommunitySpaceManagementApi {
|
||||
}
|
||||
}
|
||||
|
||||
Future<PaginationModel> fetchCommunitiesAndSpaces(
|
||||
{required String projectId, int page = 1, String search = ''}) async {
|
||||
PaginationModel paginationModel = const PaginationModel.emptyConstructor();
|
||||
|
||||
try {
|
||||
bool hasNext = false;
|
||||
await HTTPService().get(
|
||||
path: ApiEndpoints.getCommunityList.replaceAll('{projectId}', projectId),
|
||||
queryParameters: {'page': page, 'includeSpaces': true, 'size': 25, 'search': search},
|
||||
expectedResponseModel: (json) {
|
||||
try {
|
||||
List<dynamic> jsonData = json['data'] ?? [];
|
||||
hasNext = json['hasNext'] ?? false;
|
||||
int currentPage = json['page'] ?? 1;
|
||||
List<CommunityModel> communityList = jsonData.map((jsonItem) {
|
||||
return CommunityModel.fromJson(jsonItem);
|
||||
}).toList();
|
||||
|
||||
page = currentPage + 1;
|
||||
paginationModel = PaginationModel(
|
||||
pageNum: page, hasNext: hasNext, size: 25, communities: communityList);
|
||||
return paginationModel;
|
||||
} catch (_) {
|
||||
hasNext = false;
|
||||
return [];
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (_) {}
|
||||
return paginationModel;
|
||||
}
|
||||
|
||||
Future<CommunityModel?> getCommunityById(String communityId) async {
|
||||
try {
|
||||
final response = await HTTPService().get(
|
||||
|
Reference in New Issue
Block a user