Added ProjectCubit as a dependency in blocs for managing project-level state.

This commit is contained in:
hannathkadher
2025-02-15 00:36:20 +04:00
parent da445e11aa
commit e1609309cf
25 changed files with 509 additions and 268 deletions

View File

@ -13,7 +13,8 @@ import 'package:syncrow_web/utils/constants/temp_const.dart';
class CommunitySpaceManagementApi {
// Community Management APIs
Future<List<CommunityModel>> fetchCommunities({int page = 1}) async {
Future<List<CommunityModel>> fetchCommunities(String projectId,
{int page = 1}) async {
try {
List<CommunityModel> allCommunities = [];
bool hasNext = true;
@ -21,7 +22,7 @@ class CommunitySpaceManagementApi {
while (hasNext) {
await HTTPService().get(
path: ApiEndpoints.getCommunityList
.replaceAll('{projectId}', TempConst.projectId),
.replaceAll('{projectId}', projectId),
queryParameters: {'page': page},
expectedResponseModel: (json) {
try {
@ -65,11 +66,10 @@ class CommunitySpaceManagementApi {
}
Future<CommunityModel?> createCommunity(
String name, String description) async {
String name, String description, String projectId) async {
try {
final response = await HTTPService().post(
path: ApiEndpoints.createCommunity
.replaceAll('{projectId}', TempConst.projectId),
path: ApiEndpoints.createCommunity.replaceAll('{projectId}', projectId),
body: {
'name': name,
'description': description,
@ -85,12 +85,13 @@ class CommunitySpaceManagementApi {
}
}
Future<bool> updateCommunity(String communityId, String name) async {
Future<bool> updateCommunity(
String communityId, String name, String projectId) async {
try {
final response = await HTTPService().put(
path: ApiEndpoints.updateCommunity
.replaceAll('{communityId}', communityId)
.replaceAll('{projectId}', TempConst.projectId),
.replaceAll('{projectId}', projectId),
body: {
'name': name,
},
@ -105,12 +106,12 @@ class CommunitySpaceManagementApi {
}
}
Future<bool> deleteCommunity(String communityId) async {
Future<bool> deleteCommunity(String communityId, String projectId) async {
try {
final response = await HTTPService().delete(
path: ApiEndpoints.deleteCommunity
.replaceAll('{communityId}', communityId)
.replaceAll('{projectId}', TempConst.projectId),
.replaceAll('{projectId}', projectId),
expectedResponseModel: (json) {
return json['success'] ?? false;
},
@ -122,12 +123,13 @@ class CommunitySpaceManagementApi {
}
}
Future<SpacesResponse> fetchSpaces(String communityId) async {
Future<SpacesResponse> fetchSpaces(
String communityId, String projectId) async {
try {
final response = await HTTPService().get(
path: ApiEndpoints.listSpaces
.replaceAll('{communityId}', communityId)
.replaceAll('{projectId}', TempConst.projectId),
.replaceAll('{projectId}', projectId),
expectedResponseModel: (json) {
return SpacesResponse.fromJson(json);
},
@ -148,13 +150,14 @@ class CommunitySpaceManagementApi {
}
}
Future<SpaceModel?> getSpace(String communityId, String spaceId) async {
Future<SpaceModel?> getSpace(
String communityId, String spaceId, String projectId) async {
try {
final response = await HTTPService().get(
path: ApiEndpoints.getSpace
.replaceAll('{communityId}', communityId)
.replaceAll('{spaceId}', spaceId)
.replaceAll('{projectId}', TempConst.projectId),
.replaceAll('{projectId}', projectId),
expectedResponseModel: (json) {
return SpaceModel.fromJson(json['data']);
},
@ -176,7 +179,8 @@ class CommunitySpaceManagementApi {
String? spaceModelUuid,
String? icon,
List<CreateTagBodyModel>? tags,
List<CreateSubspaceModel>? subspaces}) async {
List<CreateSubspaceModel>? subspaces,
required String projectId}) async {
try {
final body = {
'spaceName': name,
@ -199,7 +203,7 @@ class CommunitySpaceManagementApi {
final response = await HTTPService().post(
path: ApiEndpoints.createSpace
.replaceAll('{communityId}', communityId)
.replaceAll('{projectId}', TempConst.projectId),
.replaceAll('{projectId}', projectId),
body: body,
expectedResponseModel: (json) {
return SpaceModel.fromJson(json['data']);
@ -212,18 +216,18 @@ class CommunitySpaceManagementApi {
}
}
Future<bool> updateSpace({
required String communityId,
required spaceId,
required String name,
String? parentId,
String? icon,
String? direction,
bool isPrivate = false,
required Offset position,
List<TagModelUpdate>? tags,
List<UpdateSubspaceTemplateModel>? subspaces,
}) async {
Future<bool> updateSpace(
{required String communityId,
required spaceId,
required String name,
String? parentId,
String? icon,
String? direction,
bool isPrivate = false,
required Offset position,
List<TagModelUpdate>? tags,
List<UpdateSubspaceTemplateModel>? subspaces,
required String projectId}) async {
try {
final body = {
'spaceName': name,
@ -243,7 +247,7 @@ class CommunitySpaceManagementApi {
path: ApiEndpoints.updateSpace
.replaceAll('{communityId}', communityId)
.replaceAll('{spaceId}', spaceId)
.replaceAll('{projectId}', TempConst.projectId),
.replaceAll('{projectId}', projectId),
body: body,
expectedResponseModel: (json) {
return json['success'] ?? false;
@ -256,13 +260,14 @@ class CommunitySpaceManagementApi {
}
}
Future<bool> deleteSpace(String communityId, String spaceId) async {
Future<bool> deleteSpace(
String communityId, String spaceId, String projectId) async {
try {
final response = await HTTPService().delete(
path: ApiEndpoints.deleteSpace
.replaceAll('{communityId}', communityId)
.replaceAll('{spaceId}', spaceId)
.replaceAll('{projectId}', TempConst.projectId),
.replaceAll('{projectId}', projectId),
expectedResponseModel: (json) {
return json['success'] ?? false;
},
@ -274,12 +279,13 @@ class CommunitySpaceManagementApi {
}
}
Future<List<SpaceModel>> getSpaceHierarchy(String communityId) async {
Future<List<SpaceModel>> getSpaceHierarchy(
String communityId, String projectId) async {
try {
final response = await HTTPService().get(
path: ApiEndpoints.getSpaceHierarchy
.replaceAll('{communityId}', communityId)
.replaceAll('{projectId}', TempConst.projectId),
.replaceAll('{projectId}', projectId),
expectedResponseModel: (json) {
final spaceModels = (json['data'] as List)
.map((spaceJson) => SpaceModel.fromJson(spaceJson))