mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
Merged with dev
This commit is contained in:
@ -12,4 +12,33 @@ class HomeApi {
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
Future fetchTerms() async {
|
||||
final response = await HTTPService().get(
|
||||
path: ApiEndpoints.terms,
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
return json['data'];
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
Future fetchPolicy() async {
|
||||
final response = await HTTPService().get(
|
||||
path: ApiEndpoints.policy,
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
return json['data'];
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
Future confirmUserAgreements(uuid) async {
|
||||
final response = await HTTPService().patch(
|
||||
path: ApiEndpoints.userAgreements.replaceAll('{userUuid}', uuid!),
|
||||
expectedResponseModel: (json) {
|
||||
return json['data'];
|
||||
});
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/selected_product_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';
|
||||
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/tag_body_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';
|
||||
@ -20,23 +22,26 @@ class CommunitySpaceManagementApi {
|
||||
.replaceAll('{projectId}', TempConst.projectId),
|
||||
queryParameters: {'page': page},
|
||||
expectedResponseModel: (json) {
|
||||
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();
|
||||
|
||||
allCommunities.addAll(communityList);
|
||||
page = currentPage + 1;
|
||||
return communityList;
|
||||
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();
|
||||
allCommunities.addAll(communityList);
|
||||
page = currentPage + 1;
|
||||
return communityList;
|
||||
} catch (_) {
|
||||
hasNext = false;
|
||||
return [];
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return allCommunities;
|
||||
} catch (e) {
|
||||
debugPrint('Error fetching communities: $e');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@ -159,16 +164,17 @@ class CommunitySpaceManagementApi {
|
||||
}
|
||||
}
|
||||
|
||||
Future<SpaceModel?> createSpace({
|
||||
required String communityId,
|
||||
required String name,
|
||||
String? parentId,
|
||||
String? direction,
|
||||
bool isPrivate = false,
|
||||
required Offset position,
|
||||
String? icon,
|
||||
required List<SelectedProduct> products,
|
||||
}) async {
|
||||
Future<SpaceModel?> createSpace(
|
||||
{required String communityId,
|
||||
required String name,
|
||||
String? parentId,
|
||||
String? direction,
|
||||
bool isPrivate = false,
|
||||
required Offset position,
|
||||
String? spaceModelUuid,
|
||||
String? icon,
|
||||
List<CreateTagBodyModel>? tags,
|
||||
List<CreateSubspaceModel>? subspaces}) async {
|
||||
try {
|
||||
final body = {
|
||||
'spaceName': name,
|
||||
@ -177,11 +183,17 @@ class CommunitySpaceManagementApi {
|
||||
'y': position.dy,
|
||||
'direction': direction,
|
||||
'icon': icon,
|
||||
'products': products.map((product) => product.toJson()).toList(),
|
||||
};
|
||||
if (parentId != null) {
|
||||
body['parentUuid'] = parentId;
|
||||
}
|
||||
if (tags != null) {
|
||||
body['tags'] = tags;
|
||||
}
|
||||
|
||||
if (spaceModelUuid != null) body['spaceModelUuid'] = spaceModelUuid;
|
||||
|
||||
if (subspaces != null) body['subspaces'] = subspaces;
|
||||
final response = await HTTPService().post(
|
||||
path: ApiEndpoints.createSpace
|
||||
.replaceAll('{communityId}', communityId)
|
||||
@ -207,7 +219,6 @@ class CommunitySpaceManagementApi {
|
||||
String? direction,
|
||||
bool isPrivate = false,
|
||||
required Offset position,
|
||||
required List<SelectedProduct> products,
|
||||
}) async {
|
||||
try {
|
||||
final body = {
|
||||
@ -217,7 +228,6 @@ class CommunitySpaceManagementApi {
|
||||
'y': position.dy,
|
||||
'direction': direction,
|
||||
'icon': icon,
|
||||
'products': products.map((product) => product.toJson()).toList(),
|
||||
};
|
||||
if (parentId != null) {
|
||||
body['parentUuid'] = parentId;
|
||||
|
63
lib/services/space_model_mang_api.dart
Normal file
63
lib/services/space_model_mang_api.dart
Normal file
@ -0,0 +1,63 @@
|
||||
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/services/api/http_service.dart';
|
||||
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 {
|
||||
final response = await HTTPService().get(
|
||||
path: ApiEndpoints.listSpaceModels
|
||||
.replaceAll('{projectId}', TempConst.projectId),
|
||||
queryParameters: {'page': page},
|
||||
expectedResponseModel: (json) {
|
||||
List<dynamic> jsonData = json['data'];
|
||||
return jsonData.map((jsonItem) {
|
||||
return SpaceTemplateModel.fromJson(jsonItem);
|
||||
}).toList();
|
||||
},
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
Future<SpaceTemplateModel?> createSpaceModel(
|
||||
CreateSpaceTemplateBodyModel spaceModel) async {
|
||||
final response = await HTTPService().post(
|
||||
path: ApiEndpoints.createSpaceModel
|
||||
.replaceAll('{projectId}', TempConst.projectId),
|
||||
showServerMessage: true,
|
||||
body: spaceModel.toJson(),
|
||||
expectedResponseModel: (json) {
|
||||
return SpaceTemplateModel.fromJson(json['data']);
|
||||
},
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
Future<String?> updateSpaceModel(
|
||||
CreateSpaceTemplateBodyModel spaceModel, String spaceModelUuid) async {
|
||||
final response = await HTTPService().put(
|
||||
path: ApiEndpoints.updateSpaceModel
|
||||
.replaceAll('{projectId}', TempConst.projectId).replaceAll('{spaceModelUuid}', spaceModelUuid),
|
||||
body: spaceModel.toJson(),
|
||||
expectedResponseModel: (json) {
|
||||
return json['message'];
|
||||
},
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
Future<SpaceTemplateModel?> getSpaceModel(String spaceModelUuid) async {
|
||||
final response = await HTTPService().get(
|
||||
path: ApiEndpoints.getSpaceModel
|
||||
.replaceAll('{projectId}', TempConst.projectId)
|
||||
.replaceAll('{spaceModelUuid}', spaceModelUuid),
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
return SpaceTemplateModel.fromJson(json['data']);
|
||||
},
|
||||
);
|
||||
return response;
|
||||
}
|
||||
}
|
219
lib/services/user_permission.dart
Normal file
219
lib/services/user_permission.dart
Normal file
@ -0,0 +1,219 @@
|
||||
import 'dart:convert';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:syncrow_web/pages/roles_and_permission/model/edit_user_model.dart';
|
||||
import 'package:syncrow_web/pages/roles_and_permission/model/role_type_model.dart';
|
||||
import 'package:syncrow_web/pages/roles_and_permission/model/roles_user_model.dart';
|
||||
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/model/permission_option_model.dart';
|
||||
import 'package:syncrow_web/services/api/http_service.dart';
|
||||
import 'package:syncrow_web/utils/constants/api_const.dart';
|
||||
|
||||
class UserPermissionApi {
|
||||
static final HTTPService _httpService = HTTPService();
|
||||
|
||||
Future<List<RolesUserModel>> fetchUsers() async {
|
||||
try {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.getUsers,
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
debugPrint('fetchUsers Response: $json');
|
||||
final List<dynamic> data =
|
||||
json['data'] ?? []; // Default to an empty list if no data
|
||||
return data.map((item) => RolesUserModel.fromJson(item)).toList();
|
||||
},
|
||||
);
|
||||
return response;
|
||||
} catch (e, stackTrace) {
|
||||
debugPrint('Error in fetchUsers: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
fetchRoles() async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.roleTypes,
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
final List<RoleTypeModel> fetchedRoles = (json['data'] as List)
|
||||
.map((item) => RoleTypeModel.fromJson(item))
|
||||
.toList();
|
||||
return fetchedRoles;
|
||||
},
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
Future<List<PermissionOption>> fetchPermission(roleUuid) async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.permission.replaceAll("roleUuid", roleUuid),
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
return (json as List)
|
||||
.map((data) => PermissionOption.fromJson(data))
|
||||
.toList();
|
||||
},
|
||||
);
|
||||
return response ?? [];
|
||||
}
|
||||
|
||||
Future<bool> sendInviteUser({
|
||||
String? firstName,
|
||||
String? lastName,
|
||||
String? email,
|
||||
String? jobTitle,
|
||||
String? phoneNumber,
|
||||
String? roleUuid,
|
||||
List<String>? spaceUuids,
|
||||
}) async {
|
||||
try {
|
||||
final body = <String, dynamic>{
|
||||
"firstName": firstName,
|
||||
"lastName": lastName,
|
||||
"email": email,
|
||||
"jobTitle": jobTitle != '' ? jobTitle : null,
|
||||
"phoneNumber": phoneNumber != '' ? phoneNumber : null,
|
||||
"roleUuid": roleUuid,
|
||||
"projectUuid": "0e62577c-06fa-41b9-8a92-99a21fbaf51c",
|
||||
"spaceUuids": spaceUuids,
|
||||
};
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.inviteUser,
|
||||
showServerMessage: true,
|
||||
body: jsonEncode(body),
|
||||
expectedResponseModel: (json) {
|
||||
if (json['statusCode'] != 400) {
|
||||
return json["success"];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
);
|
||||
print('sendInviteUser=$body');
|
||||
|
||||
return response ?? [];
|
||||
} on DioException catch (e) {
|
||||
return false;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> checkEmail(String email) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.checkEmail,
|
||||
showServerMessage: true,
|
||||
body: {"email": email},
|
||||
expectedResponseModel: (json) {
|
||||
if (json['statusCode'] != 400) {
|
||||
var message = json["message"];
|
||||
if (message is String) {
|
||||
return message;
|
||||
} else {
|
||||
return 'Unexpected message format';
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
return response ?? 'Unknown error occurred';
|
||||
} on DioException catch (e) {
|
||||
final errorMessage = e.response?.data['error'];
|
||||
return errorMessage;
|
||||
} catch (e) {
|
||||
return e.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Future<EditUserModel?> fetchUserById(userUuid) async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.getUserById.replaceAll("{userUuid}", userUuid),
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
EditUserModel res = EditUserModel.fromJson(json['data']);
|
||||
return res;
|
||||
},
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
Future<bool> editInviteUser({
|
||||
String? firstName,
|
||||
String? userId,
|
||||
String? lastName,
|
||||
String? jobTitle,
|
||||
String? phoneNumber,
|
||||
String? roleUuid,
|
||||
List<String>? spaceUuids,
|
||||
}) async {
|
||||
try {
|
||||
final body = <String, dynamic>{
|
||||
"firstName": firstName,
|
||||
"lastName": lastName,
|
||||
"jobTitle": jobTitle != '' ? jobTitle : " ",
|
||||
"phoneNumber": phoneNumber != '' ? phoneNumber : " ",
|
||||
"roleUuid": roleUuid,
|
||||
"projectUuid": "0e62577c-06fa-41b9-8a92-99a21fbaf51c",
|
||||
"spaceUuids": spaceUuids,
|
||||
};
|
||||
final response = await _httpService.put(
|
||||
path: ApiEndpoints.editUser.replaceAll('{inviteUserUuid}', userId!),
|
||||
body: jsonEncode(body),
|
||||
expectedResponseModel: (json) {
|
||||
if (json['statusCode'] != 400) {
|
||||
return json["success"];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
);
|
||||
return response;
|
||||
} on DioException catch (e) {
|
||||
return false;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> deleteUserById(userUuid) async {
|
||||
try {
|
||||
final response = await _httpService.delete(
|
||||
path: ApiEndpoints.deleteUser.replaceAll("{inviteUserUuid}", userUuid),
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
return json['success'];
|
||||
},
|
||||
);
|
||||
return response;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> changeUserStatusById(userUuid, status) async {
|
||||
try {
|
||||
Map<String, dynamic> bodya = {
|
||||
"disable": status,
|
||||
"projectUuid": "0e62577c-06fa-41b9-8a92-99a21fbaf51c"
|
||||
};
|
||||
print('changeUserStatusById==$bodya');
|
||||
print('changeUserStatusById==$userUuid');
|
||||
|
||||
final response = await _httpService.put(
|
||||
path: ApiEndpoints.changeUserStatus
|
||||
.replaceAll("{invitedUserUuid}", userUuid),
|
||||
body: bodya,
|
||||
expectedResponseModel: (json) {
|
||||
print('changeUserStatusById==${json['success']}');
|
||||
return json['success'];
|
||||
},
|
||||
);
|
||||
|
||||
return response;
|
||||
} catch (e) {
|
||||
return false;
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user