added unit devices

This commit is contained in:
hannathkadher
2024-10-30 19:16:10 +04:00
parent 5c65bac076
commit 13a4bf25b3
15 changed files with 220 additions and 88 deletions

View File

@ -1,6 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
@ -130,23 +129,43 @@ class DevicesAPI {
return response;
}
static Future<List<DeviceModel>> getDevicesByRoomId(String roomId) async {
final response = await _httpService.get(
path: ApiEndpoints.deviceByRoom,
queryParameters: {"roomUuid": roomId},
showServerMessage: false,
expectedResponseModel: (json) {
if (json == null || json.isEmpty || json == []) {
return <DeviceModel>[];
}
List<DeviceModel> devices = [];
for (var device in json) {
devices.add(DeviceModel.fromJson(device));
}
return devices;
},
);
return response;
static Future<List<DeviceModel>> getDevicesByRoomId({
required String communityUuid,
required String spaceUuid,
required String roomId,
}) async {
try {
final String path = ApiEndpoints.deviceByRoom
.replaceAll(':communityUuid', communityUuid)
.replaceAll(':spaceUuid', spaceUuid)
.replaceAll(':subSpaceUuid', roomId);
final response = await _httpService.get(
path: path,
showServerMessage: false,
expectedResponseModel: (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
print("Error fetching devices for room: $e");
// Return an empty list in case of error
return <DeviceModel>[];
}
}
static Future<List<DeviceModel>> getDevicesByGatewayId(