mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
Added include spaces to the communites api
This commit is contained in:
@ -3,27 +3,24 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_m
|
||||
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';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_response_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/create_space_template_body_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_body_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_update_model.dart';
|
||||
import 'package:syncrow_web/services/api/http_service.dart';
|
||||
import 'package:syncrow_web/utils/constants/api_const.dart';
|
||||
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
||||
|
||||
class CommunitySpaceManagementApi {
|
||||
// Community Management APIs
|
||||
Future<List<CommunityModel>> fetchCommunities(String projectId,
|
||||
{int page = 1}) async {
|
||||
{int page = 1, bool includeSpaces = false}) async {
|
||||
try {
|
||||
List<CommunityModel> allCommunities = [];
|
||||
bool hasNext = true;
|
||||
|
||||
while (hasNext) {
|
||||
await HTTPService().get(
|
||||
path: ApiEndpoints.getCommunityList
|
||||
.replaceAll('{projectId}', projectId),
|
||||
queryParameters: {'page': page},
|
||||
path: ApiEndpoints.getCommunityList.replaceAll('{projectId}', projectId),
|
||||
queryParameters: {'page': page, 'includeSpaces': includeSpaces},
|
||||
expectedResponseModel: (json) {
|
||||
try {
|
||||
List<dynamic> jsonData = json['data'] ?? [];
|
||||
@ -52,8 +49,7 @@ class CommunitySpaceManagementApi {
|
||||
Future<CommunityModel?> getCommunityById(String communityId) async {
|
||||
try {
|
||||
final response = await HTTPService().get(
|
||||
path: ApiEndpoints.getCommunityById
|
||||
.replaceAll('{communityId}', communityId),
|
||||
path: ApiEndpoints.getCommunityById.replaceAll('{communityId}', communityId),
|
||||
expectedResponseModel: (json) {
|
||||
return CommunityModel.fromJson(json['data']);
|
||||
},
|
||||
@ -65,8 +61,7 @@ class CommunitySpaceManagementApi {
|
||||
}
|
||||
}
|
||||
|
||||
Future<CommunityModel?> createCommunity(
|
||||
String name, String description, String projectId) async {
|
||||
Future<CommunityModel?> createCommunity(String name, String description, String projectId) async {
|
||||
try {
|
||||
final response = await HTTPService().post(
|
||||
path: ApiEndpoints.createCommunity.replaceAll('{projectId}', projectId),
|
||||
@ -85,8 +80,7 @@ class CommunitySpaceManagementApi {
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> updateCommunity(
|
||||
String communityId, String name, String projectId) async {
|
||||
Future<bool> updateCommunity(String communityId, String name, String projectId) async {
|
||||
try {
|
||||
final response = await HTTPService().put(
|
||||
path: ApiEndpoints.updateCommunity
|
||||
@ -123,8 +117,7 @@ class CommunitySpaceManagementApi {
|
||||
}
|
||||
}
|
||||
|
||||
Future<SpacesResponse> fetchSpaces(
|
||||
String communityId, String projectId) async {
|
||||
Future<SpacesResponse> fetchSpaces(String communityId, String projectId) async {
|
||||
try {
|
||||
final response = await HTTPService().get(
|
||||
path: ApiEndpoints.listSpaces
|
||||
@ -150,8 +143,7 @@ class CommunitySpaceManagementApi {
|
||||
}
|
||||
}
|
||||
|
||||
Future<SpaceModel?> getSpace(
|
||||
String communityId, String spaceId, String projectId) async {
|
||||
Future<SpaceModel?> getSpace(String communityId, String spaceId, String projectId) async {
|
||||
try {
|
||||
final response = await HTTPService().get(
|
||||
path: ApiEndpoints.getSpace
|
||||
@ -262,8 +254,7 @@ class CommunitySpaceManagementApi {
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> deleteSpace(
|
||||
String communityId, String spaceId, String projectId) async {
|
||||
Future<bool> deleteSpace(String communityId, String spaceId, String projectId) async {
|
||||
try {
|
||||
final response = await HTTPService().delete(
|
||||
path: ApiEndpoints.deleteSpace
|
||||
@ -281,17 +272,15 @@ class CommunitySpaceManagementApi {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<SpaceModel>> getSpaceHierarchy(
|
||||
String communityId, String projectId) async {
|
||||
Future<List<SpaceModel>> getSpaceHierarchy(String communityId, String projectId) async {
|
||||
try {
|
||||
final response = await HTTPService().get(
|
||||
path: ApiEndpoints.getSpaceHierarchy
|
||||
.replaceAll('{communityId}', communityId)
|
||||
.replaceAll('{projectId}', projectId),
|
||||
expectedResponseModel: (json) {
|
||||
final spaceModels = (json['data'] as List)
|
||||
.map((spaceJson) => SpaceModel.fromJson(spaceJson))
|
||||
.toList();
|
||||
final spaceModels =
|
||||
(json['data'] as List).map((spaceJson) => SpaceModel.fromJson(spaceJson)).toList();
|
||||
|
||||
return spaceModels;
|
||||
},
|
||||
@ -302,17 +291,16 @@ class CommunitySpaceManagementApi {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Future<List<SpaceModel>> getSpaceOnlyWithDevices(
|
||||
{String? communityId, String? projectId}) async {
|
||||
|
||||
Future<List<SpaceModel>> getSpaceOnlyWithDevices({String? communityId, String? projectId}) async {
|
||||
try {
|
||||
final response = await HTTPService().get(
|
||||
path: ApiEndpoints.spaceOnlyWithDevices
|
||||
.replaceAll('{communityId}', communityId!)
|
||||
.replaceAll('{projectId}', projectId!),
|
||||
expectedResponseModel: (json) {
|
||||
final spaceModels = (json['data'] as List)
|
||||
.map((spaceJson) => SpaceModel.fromJson(spaceJson))
|
||||
.toList();
|
||||
final spaceModels =
|
||||
(json['data'] as List).map((spaceJson) => SpaceModel.fromJson(spaceJson)).toList();
|
||||
return spaceModels;
|
||||
},
|
||||
);
|
||||
|
Reference in New Issue
Block a user