mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
updated endpoints
This commit is contained in:
@ -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) {
|
||||
|
Reference in New Issue
Block a user