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

View File

@ -24,7 +24,7 @@ class DevicesManagementApi {
showServerMessage: true,
expectedResponseModel: (json) {
List<dynamic> jsonData =
communityId.isNotEmpty && spaceId.isNotEmpty ? json['data'] : json;
communityId.isNotEmpty && spaceId.isNotEmpty ? json['data'] : json['data'];
List<AllDevicesModel> devicesList = jsonData.map((jsonItem) {
return AllDevicesModel.fromJson(jsonItem);
}).toList();
@ -33,7 +33,7 @@ class DevicesManagementApi {
);
return response;
} catch (e) {
debugPrint('Error fetching $e');
debugPrint('Error fetching device $e');
return [];
}
}
@ -44,7 +44,7 @@ class DevicesManagementApi {
path: ApiEndpoints.getDeviceStatus.replaceAll('{uuid}', uuid),
showServerMessage: true,
expectedResponseModel: (json) {
return DeviceStatus.fromJson(json);
return DeviceStatus.fromJson(json['data']);
},
);
return response;
@ -61,7 +61,7 @@ class DevicesManagementApi {
Future getPowerClampInfo(String deviceId) async {
try {
final response = await HTTPService().get(
path: ApiEndpoints.powerClamp.replaceAll('{powerClampUuid}', deviceId),
path: ApiEndpoints.getDeviceStatus.replaceAll('{uuid}', deviceId),
showServerMessage: true,
expectedResponseModel: (json) {
return json;
@ -98,6 +98,7 @@ class DevicesManagementApi {
'devicesUuid': uuids,
'code': code,
'value': value,
'operationType': 'COMMAND',
};
final response = await HTTPService().post(
@ -105,7 +106,7 @@ class DevicesManagementApi {
body: body,
showServerMessage: true,
expectedResponseModel: (json) {
return (json['successResults'] as List).isNotEmpty;
return json['success'] ?? false;
},
);
@ -125,7 +126,7 @@ class DevicesManagementApi {
if (json == null || json.isEmpty || json == []) {
return devices;
}
for (var device in json['devices']) {
for (var device in json['data']['devices']) {
devices.add(DeviceModel.fromJson(device));
}
return devices;
@ -153,7 +154,7 @@ class DevicesManagementApi {
path: ApiEndpoints.getDeviceLogs.replaceAll('{uuid}', uuid).replaceAll('{code}', code),
showServerMessage: false,
expectedResponseModel: (json) {
return DeviceReport.fromJson(json);
return DeviceReport.fromJson(json['data']);
},
);
return response;
@ -169,7 +170,7 @@ class DevicesManagementApi {
.replaceAll('{endTime}', to ?? ''),
showServerMessage: false,
expectedResponseModel: (json) {
return DeviceReport.fromJson(json);
return DeviceReport.fromJson(json['data']);
},
);
return response;
@ -185,7 +186,7 @@ class DevicesManagementApi {
queryParameters: queryParameters,
showServerMessage: true,
expectedResponseModel: (json) {
return DeviceStatus.fromJson(json['status']);
return DeviceStatus.fromJson(json['data']['status']);
},
);
return response;

View File

@ -3,13 +3,11 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_m
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/space_template_model.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_body_model.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_update_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 CommunitySpaceManagementApi {
// Community Management APIs