updated endpoints

This commit is contained in:
hannathkadher
2025-04-03 10:14:24 +04:00
parent 80c43b8046
commit a034202d76
6 changed files with 56 additions and 45 deletions

View File

@ -6,13 +6,23 @@ import 'package:syncrow_web/services/api/http_service.dart';
import 'package:syncrow_web/utils/constants/api_const.dart';
class AccessMangApi {
AccessMangApi() {
_validateEndpoints();
}
void _validateEndpoints() {
if (!ApiEndpoints.getDevices.contains('{projectId}')) {
throw Exception("Endpoint 'getDevices' must contain '{projectId}' placeholder.");
}
}
Future<List<PasswordModel>> fetchVisitorPassword(String projectId) async {
try {
final response = await HTTPService().get(
path: ApiEndpoints.visitorPassword.replaceAll('{projectId}', projectId),
path: ApiEndpoints.visitorPassword,
showServerMessage: true,
expectedResponseModel: (json) {
List<dynamic> jsonData = json;
List<dynamic> jsonData = json['data'] ?? [];
List<PasswordModel> passwordList = jsonData.map((jsonItem) {
return PasswordModel.fromJson(jsonItem);
}).toList();
@ -25,17 +35,22 @@ class AccessMangApi {
}
}
Future fetchDevices(String projectId) async {
Future fetchDoorLockDeviceList(String projectId) async {
try {
// The endpoint structure is already validated during initialization.
final response = await HTTPService().get(
path: ApiEndpoints.getDevices.replaceAll('{projectId}', projectId),
queryParameters: {
'deviceType': 'DOOR_LOCK',
},
showServerMessage: true,
expectedResponseModel: (json) {
List<dynamic> jsonData = json;
List<DeviceModel> passwordList = jsonData.map((jsonItem) {
List<dynamic> jsonData = json['data'] ?? [];
List<DeviceModel> deviceList = jsonData.map((jsonItem) {
return DeviceModel.fromJson(jsonItem);
}).toList();
return passwordList;
return deviceList;
},
);
return response;
@ -52,14 +67,15 @@ class AccessMangApi {
String? invalidTime,
List<String>? devicesUuid}) async {
final response = await HTTPService().post(
path: ApiEndpoints.sendOnlineOneTime,
path: ApiEndpoints.visitorPassword,
body: jsonEncode({
"email": email,
"passwordName": passwordName,
"password": password,
"devicesUuid": devicesUuid,
"effectiveTime": effectiveTime,
"invalidTime": invalidTime
"invalidTime": invalidTime,
"operationType": "ONLINE_ONE_TIME",
}),
showServerMessage: true,
expectedResponseModel: (json) {
@ -84,13 +100,13 @@ class AccessMangApi {
"password": password,
"effectiveTime": effectiveTime,
"invalidTime": invalidTime,
"operationType": "ONLINE_MULTIPLE_TIME",
};
if (scheduleList != null) {
body["scheduleList"] =
scheduleList.map((schedule) => schedule.toJson()).toList();
body["scheduleList"] = scheduleList.map((schedule) => schedule.toJson()).toList();
}
final response = await HTTPService().post(
path: ApiEndpoints.sendOnlineMultipleTime,
path: ApiEndpoints.visitorPassword,
body: jsonEncode(body),
showServerMessage: true,
expectedResponseModel: (json) {
@ -105,8 +121,9 @@ class AccessMangApi {
Future postOffLineOneTime(
{String? email, String? passwordName, List<String>? devicesUuid}) async {
final response = await HTTPService().post(
path: ApiEndpoints.sendOffLineOneTime,
path: ApiEndpoints.visitorPassword,
body: jsonEncode({
"operationType": "OFFLINE_ONE_TIME",
"email": email,
"passwordName": passwordName,
"devicesUuid": devicesUuid
@ -126,13 +143,14 @@ class AccessMangApi {
String? invalidTime,
List<String>? devicesUuid}) async {
final response = await HTTPService().post(
path: ApiEndpoints.sendOffLineMultipleTime,
path: ApiEndpoints.visitorPassword,
body: jsonEncode({
"email": email,
"devicesUuid": devicesUuid,
"passwordName": passwordName,
"effectiveTime": effectiveTime,
"invalidTime": invalidTime,
"operationType": "OFFLINE_MULTIPLE_TIME",
}),
showServerMessage: true,
expectedResponseModel: (json) {