fixed page load for space

This commit is contained in:
hannathkadher
2024-11-19 01:21:32 +04:00
parent 7241f78566
commit 20f94e290d
8 changed files with 303 additions and 108 deletions

View File

@ -32,8 +32,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']);
},
@ -45,8 +44,7 @@ class CommunitySpaceManagementApi {
}
}
Future<CommunityModel?> createCommunity(
String name, String description, String regionId) async {
Future<CommunityModel?> createCommunity(String name, String description, String regionId) async {
try {
final response = await HTTPService().post(
path: ApiEndpoints.createCommunity,
@ -66,12 +64,10 @@ class CommunitySpaceManagementApi {
}
}
Future<bool> updateCommunity(
String communityId, CommunityModel community) async {
Future<bool> updateCommunity(String communityId, CommunityModel community) async {
try {
final response = await HTTPService().put(
path: ApiEndpoints.updateCommunity
.replaceAll('{communityId}', communityId),
path: ApiEndpoints.updateCommunity.replaceAll('{communityId}', communityId),
body: community.toMap(),
expectedResponseModel: (json) {
return json['success'] ?? false;
@ -87,8 +83,7 @@ class CommunitySpaceManagementApi {
Future<bool> deleteCommunity(String communityId) async {
try {
final response = await HTTPService().delete(
path: ApiEndpoints.deleteCommunity
.replaceAll('{communityId}', communityId),
path: ApiEndpoints.deleteCommunity.replaceAll('{communityId}', communityId),
expectedResponseModel: (json) {
return json['success'] ?? false;
},
@ -145,20 +140,24 @@ class CommunitySpaceManagementApi {
required String communityId,
required String name,
String? parentId,
String? direction,
bool isPrivate = false,
required Offset position,
String? icon,
}) async {
try {
final body = {
'name': name,
'spaceName': name,
'isPrivate': isPrivate,
'x': position.dx,
'y': position.dy,
'direction': direction,
'icon': icon
};
if (parentId != null) {
body['parentId'] = parentId;
body['parentUuid'] = parentId;
}
print(ApiEndpoints.createSpace.replaceAll('{communityId}', communityId));
final response = await HTTPService().post(
path: ApiEndpoints.createSpace.replaceAll('{communityId}', communityId),
body: body,
@ -173,22 +172,42 @@ class CommunitySpaceManagementApi {
}
}
Future<bool> updateSpace(
String communityId, String spaceId, SpaceModel space) async {
Future<SpaceModel?> updateSpace({
required String communityId,
required spaceId,
required String name,
String? parentId,
String? icon,
String? direction,
bool isPrivate = false,
required Offset position,
}) async {
try {
final body = {
'spaceName': name,
'isPrivate': isPrivate,
'x': position.dx,
'y': position.dy,
'direction': direction,
'icon': icon
};
if (parentId != null) {
body['parentUuid'] = parentId;
}
final response = await HTTPService().put(
path: ApiEndpoints.updateSpace
.replaceAll('{communityId}', communityId)
.replaceAll('{spaceId}', spaceId),
body: space.toMap(),
body: body,
expectedResponseModel: (json) {
return json['success'] ?? false;
return SpaceModel.fromJson(json['data']);
},
);
return response;
} catch (e) {
debugPrint('Error updating space: $e');
return false;
debugPrint('Error creating space: $e');
return null;
}
}
@ -212,12 +231,9 @@ class CommunitySpaceManagementApi {
Future<List<SpaceModel>> getSpaceHierarchy(String communityId) async {
try {
final response = await HTTPService().get(
path: ApiEndpoints.getSpaceHierarchy
.replaceAll('{communityId}', communityId),
path: ApiEndpoints.getSpaceHierarchy.replaceAll('{communityId}', communityId),
expectedResponseModel: (json) {
return (json['data'] as List)
.map((spaceJson) => SpaceModel.fromJson(spaceJson))
.toList();
return (json['data'] as List).map((spaceJson) => SpaceModel.fromJson(spaceJson)).toList();
},
);
return response;