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

@ -12,14 +12,14 @@ import 'package:syncrow_web/utils/constants/api_const.dart';
import 'package:syncrow_web/utils/constants/temp_const.dart';
class DevicesManagementApi {
Future<List<AllDevicesModel>> fetchDevices(String communityId, String spaceId) async {
Future<List<AllDevicesModel>> fetchDevices(String communityId, String spaceId, String projectId) async {
try {
final response = await HTTPService().get(
path: communityId.isNotEmpty && spaceId.isNotEmpty
? ApiEndpoints.getSpaceDevices
.replaceAll('{spaceUuid}', spaceId)
.replaceAll('{communityUuid}', communityId)
.replaceAll('{projectId}', TempConst.projectId)
.replaceAll('{projectId}', projectId)
: ApiEndpoints.getAllDevices,
showServerMessage: true,
expectedResponseModel: (json) {

View File

@ -12,7 +12,8 @@ class SceneApi {
static final HTTPService _httpService = HTTPService();
// //create scene
static Future<Map<String, dynamic>> createScene(CreateSceneModel createSceneModel) async {
static Future<Map<String, dynamic>> createScene(
CreateSceneModel createSceneModel) async {
try {
debugPrint('create scene model: ${createSceneModel.toMap()}');
final response = await _httpService.post(
@ -69,14 +70,15 @@ class SceneApi {
//get scenes by community id and space id
static Future<List<ScenesModel>> getScenes(String spaceId, String communityId,
static Future<List<ScenesModel>> getScenes(
String spaceId, String communityId, String projectId,
{showInDevice = false}) async {
try {
final response = await _httpService.get(
path: ApiEndpoints.getUnitScenes
.replaceAll('{spaceUuid}', spaceId)
.replaceAll('{communityUuid}', communityId)
.replaceAll('{projectId}', TempConst.projectId),
.replaceAll('{projectId}', projectId),
queryParameters: {'showInHomePage': showInDevice},
showServerMessage: false,
expectedResponseModel: (json) {
@ -100,7 +102,8 @@ class SceneApi {
static Future<List<ScenesModel>> getAutomation(String spaceId) async {
try {
final response = await _httpService.get(
path: ApiEndpoints.getSpaceAutomation.replaceAll('{spaceUuid}', spaceId),
path:
ApiEndpoints.getSpaceAutomation.replaceAll('{spaceUuid}', spaceId),
showServerMessage: false,
expectedResponseModel: (json) {
List<ScenesModel> scenes = [];
@ -130,10 +133,12 @@ class SceneApi {
// }
//automation details
static Future<RoutineDetailsModel> getAutomationDetails(String automationId) async {
static Future<RoutineDetailsModel> getAutomationDetails(
String automationId) async {
try {
final response = await _httpService.get(
path: ApiEndpoints.getAutomationDetails.replaceAll('{automationId}', automationId),
path: ApiEndpoints.getAutomationDetails
.replaceAll('{automationId}', automationId),
showServerMessage: false,
expectedResponseModel: (json) => RoutineDetailsModel.fromMap(json),
);
@ -148,7 +153,8 @@ class SceneApi {
try {
final response = await _httpService.put(
path: ApiEndpoints.updateScene.replaceAll('{sceneId}', sceneId),
body: createSceneModel.toJson(sceneId.isNotEmpty == true ? sceneId : null),
body: createSceneModel
.toJson(sceneId.isNotEmpty == true ? sceneId : null),
expectedResponseModel: (json) {
return json;
},
@ -160,11 +166,14 @@ class SceneApi {
}
//update automation
static updateAutomation(CreateAutomationModel createAutomationModel, String automationId) async {
static updateAutomation(
CreateAutomationModel createAutomationModel, String automationId) async {
try {
final response = await _httpService.put(
path: ApiEndpoints.updateAutomation.replaceAll('{automationId}', automationId),
body: createAutomationModel.toJson(automationId.isNotEmpty == true ? automationId : null),
path: ApiEndpoints.updateAutomation
.replaceAll('{automationId}', automationId),
body: createAutomationModel
.toJson(automationId.isNotEmpty == true ? automationId : null),
expectedResponseModel: (json) {
return json;
},
@ -181,7 +190,8 @@ class SceneApi {
final response = await _httpService.get(
path: ApiEndpoints.getScene.replaceAll('{sceneId}', sceneId),
showServerMessage: false,
expectedResponseModel: (json) => RoutineDetailsModel.fromMap(json['data']),
expectedResponseModel: (json) =>
RoutineDetailsModel.fromMap(json['data']),
);
return response;
} catch (e) {
@ -190,7 +200,8 @@ class SceneApi {
}
//delete Scene
static Future<bool> deleteScene({required String unitUuid, required String sceneId}) async {
static Future<bool> deleteScene(
{required String unitUuid, required String sceneId}) async {
try {
final response = await _httpService.delete(
path: ApiEndpoints.deleteScene

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))

View File

@ -5,10 +5,10 @@ import 'package:syncrow_web/utils/constants/api_const.dart';
import 'package:syncrow_web/utils/constants/temp_const.dart';
class SpaceModelManagementApi {
Future<List<SpaceTemplateModel>> listSpaceModels({int page = 1}) async {
Future<List<SpaceTemplateModel>> listSpaceModels(
{required String projectId, int page = 1}) async {
final response = await HTTPService().get(
path: ApiEndpoints.listSpaceModels
.replaceAll('{projectId}', TempConst.projectId),
path: ApiEndpoints.listSpaceModels.replaceAll('{projectId}', projectId),
queryParameters: {'page': page},
expectedResponseModel: (json) {
List<dynamic> jsonData = json['data'];
@ -21,10 +21,9 @@ class SpaceModelManagementApi {
}
Future<SpaceTemplateModel?> createSpaceModel(
CreateSpaceTemplateBodyModel spaceModel) async {
CreateSpaceTemplateBodyModel spaceModel, String projectId) async {
final response = await HTTPService().post(
path: ApiEndpoints.createSpaceModel
.replaceAll('{projectId}', TempConst.projectId),
path: ApiEndpoints.createSpaceModel.replaceAll('{projectId}', projectId),
showServerMessage: true,
body: spaceModel.toJson(),
expectedResponseModel: (json) {
@ -34,12 +33,12 @@ class SpaceModelManagementApi {
return response;
}
Future<String?> updateSpaceModel(
CreateSpaceTemplateBodyModel spaceModel, String spaceModelUuid) async {
Future<String?> updateSpaceModel(CreateSpaceTemplateBodyModel spaceModel,
String spaceModelUuid, String projectId) async {
final response = await HTTPService().put(
path: ApiEndpoints.updateSpaceModel
.replaceAll('{projectId}', TempConst.projectId).replaceAll('{spaceModelUuid}', spaceModelUuid),
.replaceAll('{projectId}', projectId)
.replaceAll('{spaceModelUuid}', spaceModelUuid),
body: spaceModel.toJson(),
expectedResponseModel: (json) {
return json['message'];
@ -48,10 +47,11 @@ class SpaceModelManagementApi {
return response;
}
Future<SpaceTemplateModel?> getSpaceModel(String spaceModelUuid) async {
Future<SpaceTemplateModel?> getSpaceModel(
String spaceModelUuid, String projectId) async {
final response = await HTTPService().get(
path: ApiEndpoints.getSpaceModel
.replaceAll('{projectId}', TempConst.projectId)
.replaceAll('{projectId}', projectId)
.replaceAll('{spaceModelUuid}', spaceModelUuid),
showServerMessage: true,
expectedResponseModel: (json) {

View File

@ -11,10 +11,10 @@ import 'package:syncrow_web/utils/constants/api_const.dart';
class UserPermissionApi {
static final HTTPService _httpService = HTTPService();
Future<List<RolesUserModel>> fetchUsers() async {
Future<List<RolesUserModel>> fetchUsers(String projectId) async {
try {
final response = await _httpService.get(
path: ApiEndpoints.getUsers,
path: ApiEndpoints.getUsers.replaceAll('{projectUuid}', projectId),
showServerMessage: true,
expectedResponseModel: (json) {
debugPrint('fetchUsers Response: $json');
@ -34,8 +34,9 @@ class UserPermissionApi {
path: ApiEndpoints.roleTypes,
showServerMessage: true,
expectedResponseModel: (json) {
final List<RoleTypeModel> fetchedRoles =
(json['data'] as List).map((item) => RoleTypeModel.fromJson(item)).toList();
final List<RoleTypeModel> fetchedRoles = (json['data'] as List)
.map((item) => RoleTypeModel.fromJson(item))
.toList();
return fetchedRoles;
},
);
@ -47,7 +48,9 @@ class UserPermissionApi {
path: ApiEndpoints.permission.replaceAll("roleUuid", roleUuid),
showServerMessage: true,
expectedResponseModel: (json) {
return (json as List).map((data) => PermissionOption.fromJson(data)).toList();
return (json as List)
.map((data) => PermissionOption.fromJson(data))
.toList();
},
);
return response ?? [];
@ -61,6 +64,7 @@ class UserPermissionApi {
String? phoneNumber,
String? roleUuid,
List<String>? spaceUuids,
required String projectUuid,
}) async {
try {
final body = <String, dynamic>{
@ -70,7 +74,7 @@ class UserPermissionApi {
"jobTitle": jobTitle != '' ? jobTitle : null,
"phoneNumber": phoneNumber != '' ? phoneNumber : null,
"roleUuid": roleUuid,
"projectUuid": "0e62577c-06fa-41b9-8a92-99a21fbaf51c",
"projectUuid": projectUuid,
"spaceUuids": spaceUuids,
};
final response = await _httpService.post(
@ -121,9 +125,11 @@ class UserPermissionApi {
}
}
Future<EditUserModel?> fetchUserById(userUuid) async {
Future<EditUserModel?> fetchUserById(userUuid, String projectId) async {
final response = await _httpService.get(
path: ApiEndpoints.getUserById.replaceAll("{userUuid}", userUuid),
path: ApiEndpoints.getUserById
.replaceAll("{userUuid}", userUuid)
.replaceAll("{projectId}", projectId),
showServerMessage: true,
expectedResponseModel: (json) {
EditUserModel res = EditUserModel.fromJson(json['data']);
@ -141,6 +147,7 @@ class UserPermissionApi {
String? phoneNumber,
String? roleUuid,
List<String>? spaceUuids,
required String projectUuid,
}) async {
try {
final body = <String, dynamic>{
@ -149,7 +156,7 @@ class UserPermissionApi {
"jobTitle": jobTitle != '' ? jobTitle : " ",
"phoneNumber": phoneNumber != '' ? phoneNumber : " ",
"roleUuid": roleUuid,
"projectUuid": "0e62577c-06fa-41b9-8a92-99a21fbaf51c",
"projectUuid": projectUuid,
"spaceUuids": spaceUuids,
};
final response = await _httpService.put(
@ -186,15 +193,16 @@ class UserPermissionApi {
}
}
Future<bool> changeUserStatusById(userUuid, status) async {
Future<bool> changeUserStatusById(userUuid, status, String projectUuid) async {
try {
Map<String, dynamic> bodya = {
"disable": status,
"projectUuid": "0e62577c-06fa-41b9-8a92-99a21fbaf51c"
"projectUuid": projectUuid
};
final response = await _httpService.put(
path: ApiEndpoints.changeUserStatus.replaceAll("{invitedUserUuid}", userUuid),
path: ApiEndpoints.changeUserStatus
.replaceAll("{invitedUserUuid}", userUuid),
body: bodya,
expectedResponseModel: (json) {
return json['success'];