refactored rbac services

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-09-27 08:45:32 +08:00
parent 1cc2a70a7f
commit ba89592496
16 changed files with 164 additions and 357 deletions

View File

@ -66,7 +66,7 @@ class ModuleObjectsBloc extends Bloc<ModuleObjectsEvent, ModuleObjectsState> {
emit(ModuleObjectLoadingState());
try {
bool success = await RbacModuleObjectsServices.instance
.deleteRbacModuleObject(moduleObjectId: event.moduleObjectId);
.delete(moduleObjectId: event.moduleObjectId);
if (success) {
moduleObjects
.removeWhere((element) => element.id == event.moduleObjectId);

View File

@ -1,6 +1,5 @@
import 'dart:convert';
import 'package:unit2/screens/profile/components/other_information/org_membership/add_modal.dart';
import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart';
@ -10,17 +9,15 @@ import 'package:http/http.dart' as http;
class AgencyServices {
static final AgencyServices _instance = AgencyServices();
static AgencyServices get instance => _instance;
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
String xClientKeySecret = "unitcYqAN7GGalyz";
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientSecret
};
String path = Url.instance.postAgencies();
Future<List<Agency>> getAgencies() async {
List<Agency> agencies = [];
String path = Url.instance.agencies();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
try {
http.Response response = await Request.instance
.getRequest(path: path, headers: headers, param: {});
@ -38,34 +35,30 @@ class AgencyServices {
}
return agencies;
}
Future<Map<dynamic,dynamic>>add({required Agency agency})async{
Map<dynamic, dynamic> statusResponse = {};
String path = Url.instance.postAgencies();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
Future<Map<dynamic, dynamic>> add({required Agency agency}) async {
Map<dynamic, dynamic> statusResponse = {};
Map body = {
"name":agency.name,
"category_id":agency.category!.id,
"private_entity":agency.privateEntity,
"contact_info":null,
"name": agency.name,
"category_id": agency.category!.id,
"private_entity": agency.privateEntity,
"contact_info": null,
};
try{
http.Response response = await Request.instance.postRequest(param: {},path: path, body: body,headers: headers);
if(response.statusCode == 201){
try {
http.Response response = await Request.instance
.postRequest(param: {}, path: path, body: body, headers: headers);
if (response.statusCode == 201) {
Map data = jsonDecode(response.body);
statusResponse = data;
} else {
Map data = jsonDecode(response.body);
statusResponse = data;
}else{
Map data = jsonDecode(response.body);
String message = data['message'];
statusResponse.addAll({'message': message});
statusResponse.addAll(
{'success': false},
);
}
}catch(e){
} catch (e) {
throw e.toString();
}
return statusResponse;

View File

@ -1,24 +1,22 @@
import 'dart:convert';
import 'package:unit2/model/profile/assigned_area.dart';
import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/urls.dart';
import 'package:http/http.dart' as http;
import '../../../utils/request.dart';
class RbacAssignedAreaServices {
static final RbacAssignedAreaServices _instance = RbacAssignedAreaServices();
static RbacAssignedAreaServices get instance => _instance;
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
String xClientKeySecret = "unitcYqAN7GGalyz";
String path = Url.instance.getAssignAreas();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientSecret
};
Future<List<UserAssignedArea>> getAssignedArea({required int id}) async {
List<UserAssignedArea> userAssignedAreas = [];
String path = Url.instance.getAssignAreas();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
Map<String, String> param = {
"assigned_role__user__id": id.toString(),
};
@ -39,20 +37,18 @@ class RbacAssignedAreaServices {
}
return userAssignedAreas;
}
Future<bool> deleteAssignedArea({required int areaId}) async {
Future<bool> deleteAssignedArea({required int areaId}) async {
bool success = false;
String path = "${Url.instance.getAssignAreas()}$areaId/";
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
try {
http.Response response = await Request.instance
.deleteRequest(path: path, headers: headers, body: {}, param: {});
http.Response response = await Request.instance.deleteRequest(
path: "${path + areaId.toString()}/",
headers: headers,
body: {},
param: {});
if (response.statusCode == 200) {
success = true;
}else{
} else {
success = false;
}
} catch (e) {
@ -60,28 +56,30 @@ class RbacAssignedAreaServices {
}
return success;
}
Future<Map<dynamic, dynamic>> add ({required int userId, required int roleId, required int areaTypeId, required String areaId}) async{
String path = Url.instance.getAssignAreas();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
Map<dynamic, dynamic>? responseStatus = {};
Future<Map<dynamic, dynamic>> add(
{required int userId,
required int roleId,
required int areaTypeId,
required String areaId}) async {
Map<dynamic, dynamic>? responseStatus = {};
Map body = {
"user_id":userId,
"role_id":roleId,
"assigned_areas": [{"areatypeid":areaTypeId,"areaid":areaId}]
"user_id": userId,
"role_id": roleId,
"assigned_areas": [
{"areatypeid": areaTypeId, "areaid": areaId}
]
};
try{
http.Response response = await Request.instance.postRequest(path: path, headers: headers, body: body, param: {});
if(response.statusCode == 201){
Map data = jsonDecode(response.body);
try {
http.Response response = await Request.instance
.postRequest(path: path, headers: headers, body: body, param: {});
if (response.statusCode == 201) {
Map data = jsonDecode(response.body);
responseStatus = data;
} else {
responseStatus.addAll({'success': false});
}
}catch(e){
} catch (e) {
throw e.toString();
}
return responseStatus;

View File

@ -1,7 +1,6 @@
import 'dart:convert';
import 'package:unit2/model/login_data/user_info/module.dart';
import 'package:http/http.dart' as http;
import 'package:unit2/utils/global.dart';
import '../../../model/rbac/rbac_rbac.dart';
import '../../../utils/request.dart';
import '../../../utils/urls.dart';
@ -10,16 +9,14 @@ class RbacModuleObjectsServices {
static final RbacModuleObjectsServices _instance =
RbacModuleObjectsServices();
static RbacModuleObjectsServices get instance => _instance;
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
String xClientKeySecret = "unitcYqAN7GGalyz";
Future<List<ModuleObjects>> getModuleObjects() async {
List<ModuleObjects> moduleObjects = [];
String path = Url.instance.getModuleObjects();
Map<String, String> headers = {
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
'X-Client-Secret':xClientSecret
};
String path = Url.instance.getModuleObjects();
Future<List<ModuleObjects>> getModuleObjects() async {
List<ModuleObjects> moduleObjects = [];
try {
http.Response response = await Request.instance
.getRequest(param: {}, path: path, headers: headers);
@ -38,19 +35,12 @@ class RbacModuleObjectsServices {
return moduleObjects;
}
////Add
Future<Map<dynamic, dynamic>> add({
required int assignerId,
required int? moduleId,
required List<int> objectsId,
}) async {
String path = Url.instance.getModuleObjects();
Map<dynamic, dynamic> statusResponse = {};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
Map body = {
"module_id": moduleId,
"objects": objectsId,
@ -76,17 +66,11 @@ class RbacModuleObjectsServices {
return statusResponse;
}
Future<bool> deleteRbacModuleObject({required int moduleObjectId}) async {
Future<bool> delete({required int moduleObjectId}) async {
bool success = false;
String path = "${Url.instance.getModuleObjects()}$moduleObjectId/";
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
try {
http.Response response = await Request.instance
.deleteRequest(path: path, headers: headers, body: {}, param: {});
.deleteRequest(path: "${path+moduleObjectId.toString()}/", headers: headers, body: {}, param: {});
if (response.statusCode == 200) {
success = true;
}

View File

@ -1,24 +1,21 @@
import 'dart:convert';
import 'package:unit2/model/rbac/rbac.dart';
import 'package:http/http.dart' as http;
import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/request.dart';
import '../../../utils/urls.dart';
class RbacModuleServices {
static final RbacModuleServices _instance = RbacModuleServices();
static RbacModuleServices get instance => _instance;
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
String xClientKeySecret = "unitcYqAN7GGalyz";
Future<List<RBAC>> getRbacModule() async {
List<RBAC> modules = [];
String path = Url.instance.getModules();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
'X-Client-Key':xClientKey,
'X-Client-Secret':xClientSecret
};
Future<List<RBAC>> getRbacModule() async {
List<RBAC> modules = [];
try {
http.Response response = await Request.instance
.getRequest(param: {}, path: path, headers: headers);
@ -43,13 +40,7 @@ class RbacModuleServices {
required String? slug,
required String? short,
required int id}) async {
String path = Url.instance.getModules();
Map<dynamic, dynamic> statusResponse = {};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
String? newSlug = slug?.replaceAll(" ", "-");
Map body = {
"name": name,
@ -88,13 +79,7 @@ class RbacModuleServices {
required int? createdBy,
required int updatedBy,
}) async {
String path = "${Url.instance.getModules()}$moduleId/";
Map<dynamic, dynamic> statusResponse = {};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
String? newSlug = slug?.replaceAll(" ", "-");
Map body = {
"name": name,
@ -106,7 +91,7 @@ class RbacModuleServices {
};
try {
http.Response response = await Request.instance
.putRequest(path: path, body: body, headers: headers, param: {});
.putRequest(path: "${path+moduleId.toString()}/", body: body, headers: headers, param: {});
if (response.statusCode == 200) {
Map data = jsonDecode(response.body);
statusResponse = data;
@ -127,14 +112,9 @@ class RbacModuleServices {
Future<bool> deleteRbacModule({required int moduleId}) async {
bool success = false;
String path = "${Url.instance.getModules()}$moduleId/";
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
try {
http.Response response = await Request.instance
.deleteRequest(path: path, headers: headers, body: {}, param: {});
.deleteRequest(path: '${path+moduleId.toString()}/', headers: headers, body: {}, param: {});
if (response.statusCode == 200) {
success = true;
}

View File

@ -1,24 +1,21 @@
import 'dart:convert';
import 'package:unit2/model/rbac/rbac.dart';
import 'package:http/http.dart' as http;
import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/request.dart';
import '../../../utils/urls.dart';
class RbacObjectServices {
static final RbacObjectServices _instance = RbacObjectServices();
static RbacObjectServices get instance => _instance;
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
String xClientKeySecret = "unitcYqAN7GGalyz";
Future<List<RBAC>> getRbacObjects() async {
List<RBAC> objects = [];
String path = Url.instance.getObject();
Map<String, String> headers = {
String path = Url.instance.getObject();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
'X-Client-Secret': xClientSecret
};
Future<List<RBAC>> getRbacObjects() async {
List<RBAC> objects = [];
try {
http.Response response = await Request.instance
.getRequest(param: {}, path: path, headers: headers);
@ -43,13 +40,7 @@ class RbacObjectServices {
required String? slug,
required String? short,
required int id}) async {
String path = Url.instance.getObject();
Map<dynamic, dynamic> statusResponse = {};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
String? newSlug = slug?.replaceAll(" ", "-");
Map body = {
"name": name,
@ -67,7 +58,7 @@ class RbacObjectServices {
} else {
Map data = jsonDecode(response.body);
String message = data['message'];
statusResponse.addAll({'message': "Error Adding Object"});
statusResponse.addAll({'message': message});
statusResponse.addAll(
{'success': false},
);
@ -87,13 +78,8 @@ class RbacObjectServices {
required int? createdBy,
required int updatedBy,
}) async {
String path = "${Url.instance.getObject()}$objectId/";
Map<dynamic, dynamic> statusResponse = {};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
String? newSlug = slug?.replaceAll(" ", "-");
Map body = {
"name": name,
@ -104,14 +90,14 @@ class RbacObjectServices {
};
try {
http.Response response = await Request.instance
.putRequest(path: path, body: body, headers: headers, param: {});
.putRequest(path: "${path+objectId.toString()}/", body: body, headers: headers, param: {});
if (response.statusCode == 200) {
Map data = jsonDecode(response.body);
statusResponse = data;
} else {
Map data = jsonDecode(response.body);
String message = data['message'];
statusResponse.addAll({'message': "Error Updating Object"});
statusResponse.addAll({'message': message});
statusResponse.addAll(
{'success': false},
);
@ -124,15 +110,9 @@ class RbacObjectServices {
Future<bool> deleteRbacRole({required int objectId}) async {
bool success = false;
String path = "${Url.instance.getObject()}$objectId/";
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
try {
http.Response response = await Request.instance
.deleteRequest(path: path, headers: headers, body: {}, param: {});
.deleteRequest(path: "${path+objectId.toString()}/", headers: headers, body: {}, param: {});
if (response.statusCode == 200) {
success = true;
}

View File

@ -1,24 +1,21 @@
import 'dart:convert';
import 'package:unit2/model/rbac/rbac.dart';
import 'package:http/http.dart' as http;
import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/request.dart';
import '../../../utils/urls.dart';
class RbacOperationServices {
static final RbacOperationServices _instance = RbacOperationServices();
static RbacOperationServices get instance => _instance;
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
String xClientKeySecret = "unitcYqAN7GGalyz";
Future<List<RBAC>> getRbacOperations() async {
List<RBAC> roles = [];
String path = Url.instance.getOperations();
Map<String, String> headers = {
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
'X-Client-Secret': xClientSecret
};
Future<List<RBAC>> getRbacOperations() async {
List<RBAC> roles = [];
try {
http.Response response = await Request.instance
.getRequest(param: {}, path: path, headers: headers);
@ -43,13 +40,7 @@ class RbacOperationServices {
required String? slug,
required String? short,
required int id}) async {
String path = Url.instance.getOperations();
Map<dynamic, dynamic> statusResponse = {};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
String? newSlug = slug?.replaceAll(" ", "-");
Map body = {
"name": name,
@ -87,13 +78,7 @@ class RbacOperationServices {
required int? createdBy,
required int updatedBy,
}) async {
String path = "${Url.instance.getRbacOperations()}$operationId/";
Map<dynamic, dynamic> statusResponse = {};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
String? newSlug = slug?.replaceAll(" ", "-");
Map body = {
"name": name,
@ -104,7 +89,7 @@ class RbacOperationServices {
};
try {
http.Response response = await Request.instance
.putRequest(path: path, body: body, headers: headers, param: {});
.putRequest(path: '${path+operationId.toString()}/', body: body, headers: headers, param: {});
if (response.statusCode == 200) {
Map data = jsonDecode(response.body);
statusResponse = data;
@ -124,15 +109,9 @@ class RbacOperationServices {
Future<bool> delete({required int operation}) async {
bool success = false;
String path = "${Url.instance.getRbacOperations()}$operation/";
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
try {
http.Response response = await Request.instance
.deleteRequest(path: path, headers: headers, body: {}, param: {});
.deleteRequest(path: '${path+operation.toString()}/', headers: headers, body: {}, param: {});
if (response.statusCode == 200) {
success = true;
}

View File

@ -1,6 +1,7 @@
import 'dart:convert';
import 'package:unit2/model/rbac/permission_assignment.dart';
import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart';
import 'package:http/http.dart' as http;
@ -9,15 +10,14 @@ class RbacPermissionAssignmentServices {
static final RbacPermissionAssignmentServices _instance =
RbacPermissionAssignmentServices();
static RbacPermissionAssignmentServices get instance => _instance;
String path = Url.instance.getPermissionAssignment();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z",
'X-Client-Secret': "unitcYqAN7GGalyz"
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientSecret
};
Future<List<PermissionAssignment>> getPermissionAssignment() async {
List<PermissionAssignment> permissionAssignments = [];
String path = Url.instance.getPermissionAssignment();
try {
http.Response response = await Request.instance
.getRequest(param: {}, path: path, headers: headers);
@ -25,7 +25,6 @@ class RbacPermissionAssignmentServices {
Map data = jsonDecode(response.body);
if (data['data'] != null) {
for (var rbac in data['data']) {
PermissionAssignment permissionAssignment =
PermissionAssignment.fromJson(rbac);
permissionAssignments.add(permissionAssignment);
@ -40,10 +39,9 @@ class RbacPermissionAssignmentServices {
Future<bool> deletePermissionAssignment({required int id}) async {
bool success = false;
String path = "${Url.instance.getPermissionAssignment()}$id/";
try {
http.Response response = await Request.instance
.deleteRequest(path: path, headers: headers, body: {}, param: {});
.deleteRequest(path: "${path+id.toString()}/", headers: headers, body: {}, param: {});
if (response.statusCode == 200) {
success = true;
}
@ -57,7 +55,6 @@ class RbacPermissionAssignmentServices {
{required int assignerId,
required List<int> opsId,
required int roleId}) async {
String path = Url.instance.getPermissionAssignment();
Map<dynamic, dynamic> statusResponse = {};
Map body = {
"role_id": roleId,

View File

@ -1,25 +1,21 @@
import 'dart:convert';
import 'package:unit2/model/rbac/permission.dart';
import 'package:unit2/model/rbac/rbac.dart';
import 'package:http/http.dart' as http;
import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/request.dart';
import '../../../utils/urls.dart';
class RbacPermissionServices {
static final RbacPermissionServices _instance = RbacPermissionServices();
static RbacPermissionServices get instance => _instance;
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
String xClientKeySecret = "unitcYqAN7GGalyz";
String path = Url.instance.getPersmissions();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key':xClientKey,
'X-Client-Secret': xClientSecret
};
Future<List<RBACPermission>> getRbacPermission() async {
List<RBACPermission> permissions = [];
String path = Url.instance.getPersmissions();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
try {
http.Response response = await Request.instance
.getRequest(param: {}, path: path, headers: headers);
@ -46,13 +42,7 @@ class RbacPermissionServices {
required int? objectId,
required List<int> operationsId,
}) async {
String path = Url.instance.getPersmissions();
Map<dynamic, dynamic> statusResponse = {};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
Map body = {
"object_id": objectId,
"operations": operationsId,
@ -80,15 +70,9 @@ class RbacPermissionServices {
Future<bool> deletePermission ({required int permissionId}) async {
bool success = false;
String path = "${Url.instance.getPersmissions()}$permissionId/";
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
try {
http.Response response = await Request.instance
.deleteRequest(path: path, headers: headers, body: {}, param: {});
.deleteRequest(path: "${path+permissionId.toString()}/", headers: headers, body: {}, param: {});
if (response.statusCode == 200) {
success = true;
}

View File

@ -1,30 +1,27 @@
import 'dart:convert';
import 'package:unit2/model/rbac/assigned_role.dart';
import 'package:unit2/model/rbac/rbac.dart';
import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart';
import 'package:http/http.dart' as http;
import '../../../model/profile/basic_information/primary-information.dart';
class RbacRoleAssignmentServices {
static final RbacRoleAssignmentServices _instance =
RbacRoleAssignmentServices();
static RbacRoleAssignmentServices get instance => _instance;
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
String xClientKeySecret = "unitcYqAN7GGalyz";
Future<List<AssignedRole>> getAssignedRoles(
{required String firstname, required String lastname}) async {
List<AssignedRole> assignedRoles = [];
String path = Url.instance.getRoleAssignment();
String path = Url.instance.getRoleAssignment();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
'X-Client-Secret': xClientSecret
};
Future<List<AssignedRole>> getAssignedRoles(
{required String firstname, required String lastname}) async {
List<AssignedRole> assignedRoles = [];
Map<String, String> param = {
"user__first_name__icontains": firstname,
"user__last_name__icontains": lastname
@ -49,15 +46,9 @@ class RbacRoleAssignmentServices {
Future<bool> deleteAssignedRole({required int roleId}) async {
bool success = false;
String path = "${Url.instance.getRoleAssignment()}$roleId/";
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
try {
http.Response response = await Request.instance
.deleteRequest(path: path, headers: headers, body: {}, param: {});
.deleteRequest(path: '${path+roleId.toString()}/', headers: headers, body: {}, param: {});
if (response.statusCode == 200) {
success = true;
}
@ -72,13 +63,7 @@ class RbacRoleAssignmentServices {
required int? assignerId,
required List<int> roles,
}) async {
String path = Url.instance.getRoleAssignment();
Map<dynamic, dynamic> statusResponse = {};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
Map body = {
"user_id": userId,
"roles": roles,

View File

@ -1,26 +1,23 @@
import 'dart:convert';
import 'package:unit2/model/rbac/role_extend.dart';
import 'package:unit2/model/rbac/role_under.dart';
import 'package:http/http.dart' as http;
import 'package:unit2/utils/global.dart';
import '../../../utils/request.dart';
import '../../../utils/urls.dart';
class RbacRoleExtendServices {
static final RbacRoleExtendServices _instance = RbacRoleExtendServices();
static RbacRoleExtendServices get instance => _instance;
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
String xClientKeySecret = "unitcYqAN7GGalyz";
String path = Url.instance.getRoleExtend();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientSecret
};
Future<List<RolesExtend>> getRolesExtend() async {
List<RolesExtend> rolesextend = [];
String path = Url.instance.getRoleExtend();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
// try {
try {
http.Response response = await Request.instance
.getRequest(param: {}, path: path, headers: headers);
if (response.statusCode == 200) {
@ -32,9 +29,9 @@ class RbacRoleExtendServices {
}
}
}
// } catch (e) {
// throw e.toString();
// }
} catch (e) {
throw e.toString();
}
return rolesextend;
}
@ -43,13 +40,7 @@ class RbacRoleExtendServices {
required int? roleId,
required List<int> rolesExtendsId,
}) async {
String path = Url.instance.getRoleExtend();
Map<dynamic, dynamic> statusResponse = {};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
Map body = {
"role_main_id": roleId,
"roles_extend": rolesExtendsId,
@ -77,14 +68,12 @@ class RbacRoleExtendServices {
Future<bool> delete({required int roleExtendId}) async {
bool success = false;
String path = "${Url.instance.getRoleExtend()}$roleExtendId/";
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
try {
http.Response response = await Request.instance
.deleteRequest(path: path, headers: headers, body: {}, param: {});
http.Response response = await Request.instance.deleteRequest(
path: '${path + roleExtendId.toString()}/',
headers: headers,
body: {},
param: {});
if (response.statusCode == 200) {
success = true;
}

View File

@ -1,9 +1,8 @@
import 'dart:convert';
import 'package:unit2/model/login_data/user_info/module.dart';
import 'package:http/http.dart' as http;
import 'package:unit2/model/rbac/role_module.dart';
import '../../../model/rbac/rbac_rbac.dart';
import 'package:unit2/utils/global.dart';
import '../../../utils/request.dart';
import '../../../utils/urls.dart';
@ -11,17 +10,14 @@ class RbacRoleModuleServices {
static final RbacRoleModuleServices _instance =
RbacRoleModuleServices();
static RbacRoleModuleServices get instance => _instance;
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
String xClientKeySecret = "unitcYqAN7GGalyz";
Future<List<RoleModules>> getRoleModules() async {
List<RoleModules> roleModules = [];
String path = Url.instance.getRoleModules();
Map<String, String> headers = {
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
'X-Client-Secret': xClientSecret
};
Future<List<RoleModules>> getRoleModules() async {
List<RoleModules> roleModules = [];
try {
http.Response response = await Request.instance
.getRequest(param: {}, path: path, headers: headers);
@ -46,13 +42,7 @@ class RbacRoleModuleServices {
required int? roleId,
required List<int> moduleIds,
}) async {
String path = Url.instance.getRoleModules();
Map<dynamic, dynamic> statusResponse = {};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
Map body = {
"role_id": roleId,
"modules": moduleIds,
@ -80,15 +70,9 @@ class RbacRoleModuleServices {
Future<bool> deleteRbacRoleModule({required int moduleObjectId}) async {
bool success = false;
String path = "${Url.instance.getRoleModules()}$moduleObjectId/";
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
try {
http.Response response = await Request.instance
.deleteRequest(path: path, headers: headers, body: {}, param: {});
.deleteRequest(path: "${path+moduleObjectId.toString()}/", headers: headers, body: {}, param: {});
if (response.statusCode == 200) {
success = true;
}

View File

@ -1,25 +1,21 @@
import 'dart:convert';
import 'package:unit2/model/rbac/rbac.dart';
import 'package:unit2/sevices/profile/education_services.dart';
import 'package:http/http.dart' as http;
import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/request.dart';
import '../../../utils/urls.dart';
class RbacRoleServices {
static final RbacRoleServices _instance = RbacRoleServices();
static RbacRoleServices get instance => _instance;
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
String xClientKeySecret = "unitcYqAN7GGalyz";
String path = Url.instance.getRbacRoles();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientSecret
};
Future<List<RBAC>> getRbacRoles() async {
List<RBAC> roles = [];
String path = Url.instance.getRbacRoles();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
try {
http.Response response = await Request.instance
.getRequest(param: {}, path: path, headers: headers);
@ -45,13 +41,7 @@ class RbacRoleServices {
required String? slug,
required String? short,
required int id}) async {
String path = Url.instance.getRbacRoles();
Map<dynamic, dynamic> statusResponse = {};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
String? newSlug = slug?.replaceAll(" ", "-");
Map body = {
"name": name,
@ -67,7 +57,7 @@ class RbacRoleServices {
Map data = jsonDecode(response.body);
statusResponse = data;
} else {
Map data = jsonDecode(response.body);
Map data = jsonDecode(response.body);
String message = data['message'];
statusResponse.addAll({'message': message});
statusResponse.addAll(
@ -89,13 +79,7 @@ class RbacRoleServices {
required int? createdBy,
required int updatedBy,
}) async {
String path = "${Url.instance.getRbacRoles()}$roleId/";
Map<dynamic, dynamic> statusResponse = {};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
String? newSlug = slug?.replaceAll(" ", "-");
Map body = {
"name": name,
@ -105,8 +89,11 @@ class RbacRoleServices {
"updated_by_id": updatedBy
};
try {
http.Response response = await Request.instance
.putRequest(path: path, body: body, headers: headers, param: {});
http.Response response = await Request.instance.putRequest(
path: "${path + roleId.toString()}/",
body: body,
headers: headers,
param: {});
if (response.statusCode == 200) {
Map data = jsonDecode(response.body);
statusResponse = data;
@ -126,15 +113,12 @@ class RbacRoleServices {
Future<bool> deleteRbacRole({required int roleId}) async {
bool success = false;
String path = "${Url.instance.getRbacRoles()}$roleId/";
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
try {
http.Response response = await Request.instance
.deleteRequest(path: path, headers: headers, body: {}, param: {});
http.Response response = await Request.instance.deleteRequest(
path: "${path + roleId.toString()}/",
headers: headers,
body: {},
param: {});
if (response.statusCode == 200) {
success = true;
}

View File

@ -2,23 +2,21 @@ import 'dart:convert';
import 'package:unit2/model/rbac/role_under.dart';
import 'package:http/http.dart' as http;
import 'package:unit2/utils/global.dart';
import '../../../utils/request.dart';
import '../../../utils/urls.dart';
class RbacRoleUnderServices {
static final RbacRoleUnderServices _instance = RbacRoleUnderServices();
static RbacRoleUnderServices get instance => _instance;
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
String xClientKeySecret = "unitcYqAN7GGalyz";
Future<List<RolesUnder>> getRolesUnder() async {
List<RolesUnder> rolesUnder = [];
String path = Url.instance.getRolesUnder();
String path = Url.instance.getRolesUnder();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
'X-Client-Secret': xClientSecret
};
Future<List<RolesUnder>> getRolesUnder() async {
List<RolesUnder> rolesUnder = [];
try {
http.Response response = await Request.instance
.getRequest(param: {}, path: path, headers: headers);
@ -42,13 +40,8 @@ class RbacRoleUnderServices {
required int? roleId,
required List<int> rolesId,
}) async {
String path = Url.instance.getRolesUnder();
Map<dynamic, dynamic> statusResponse = {};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
Map body = {
"role_main_id": roleId,
"roles_under": rolesId,
@ -76,15 +69,9 @@ class RbacRoleUnderServices {
Future<bool> deleteRbacRoleUnder({required int roleUnderId}) async {
bool success = false;
String path = "${Url.instance.getRolesUnder ()}$roleUnderId/";
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
try {
http.Response response = await Request.instance
.deleteRequest(path: path, headers: headers, body: {}, param: {});
.deleteRequest(path: "${path+roleUnderId.toString()}/", headers: headers, body: {}, param: {});
if (response.statusCode == 200) {
success = true;
}

View File

@ -1,27 +1,24 @@
import 'dart:convert';
import 'package:unit2/model/utils/position.dart';
import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart';
import 'package:http/http.dart' as http;
import '../../../model/rbac/rbac_station.dart';
import '../../../model/rbac/station_type.dart';
import '../../../model/roles/pass_check/station_assign_area.dart';
class RbacStationServices {
static final RbacStationServices _instance = RbacStationServices();
static RbacStationServices get instance => _instance;
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
String xClientKeySecret = "unitcYqAN7GGalyz";
Future<List<RbacStation>> getStations({required String agencyId}) async {
List<RbacStation> stations = [];
String path = Url.instance.getStation();
Map<String, String> param = {"government_agency_id": agencyId.toString()};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
'X-Client-Secret': xClientSecret
};
Future<List<RbacStation>> getStations({required String agencyId}) async {
List<RbacStation> stations = [];
Map<String, String> param = {"government_agency_id": agencyId.toString()};
try {
http.Response response = await Request.instance
.getRequest(param: param, path: path, headers: headers);
@ -42,9 +39,6 @@ class RbacStationServices {
Future<List<StationType>> getStationTypes() async {
String path = Url.instance.getStationType();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
};
List<StationType> stationTypes = [];
try {
@ -67,11 +61,7 @@ class RbacStationServices {
Future<List<PositionTitle>> getPositionTitle() async {
String path = Url.instance.getPositionTitle();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
};
List<PositionTitle> positions = [];
try {
http.Response response = await Request.instance
.getRequest(path: path, param: {}, headers: headers);
@ -93,13 +83,7 @@ class RbacStationServices {
Future<Map<dynamic, dynamic>> addStation(
{required RbacStation station}) async {
Map<dynamic, dynamic> statusResponse = {};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
String path = Url.instance.postStation();
try {
Map body = {
"station_name": station.stationName,

View File

@ -10,7 +10,6 @@ double safeAreaHorizontal = 0;
double safeAreaVertical = 0;
double safeBlockHorizontal = 0;
double safeBlockVertical = 0;
const xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
const xClientSecret = "unitcYqAN7GGalyz";
String? globalFistname;