all_devices and Restrict_user

This commit is contained in:
mohammad
2025-01-29 14:10:38 +03:00
parent d72253e3de
commit c578d63134
29 changed files with 1402 additions and 310 deletions

View File

@ -51,11 +51,14 @@ class DevicesAPI {
static Future<Map<String, dynamic>> controlDevice(
DeviceControlModel controlModel, String deviceId) async {
try {
print('object-*/-*/-*/${controlModel.toJson()}');
final response = await _httpService.post(
path: ApiEndpoints.controlDevice.replaceAll('{deviceUuid}', deviceId),
body: controlModel.toJson(),
showServerMessage: true,
expectedResponseModel: (json) {
print('object-*/-*/-*/${json}');
return json;
},
);
@ -561,4 +564,45 @@ class DevicesAPI {
);
return response;
}
static Future<List<DeviceModel>> getAllDevices({
required String communityUuid,
required String spaceUuid,
}) async {
print('communityUuid=$communityUuid');
print('spaceUuid=$spaceUuid');
print('projectUuid=${TempConst.projectId}');
try {
final String path = ApiEndpoints.getAllDevices
.replaceAll('{communityUuid}', communityUuid)
.replaceAll('{spaceUuid}', spaceUuid)
.replaceAll('{projectUuid}', TempConst.projectId);
final response = await _httpService.get(
path: path,
showServerMessage: false,
expectedResponseModel: (json) {
print('response-*/-*/$json');
final data = json['data'];
if (data == null || data.isEmpty) {
return <DeviceModel>[];
}
if (json == null || json.isEmpty || json == []) {
return <DeviceModel>[];
}
return data
.map<DeviceModel>((device) => DeviceModel.fromJson(device))
.toList();
},
);
return response;
} catch (e) {
// Log the error if needed
// Return an empty list in case of error
return <DeviceModel>[];
}
}
}