Add functionality to fetch devices by room ID

Added a new method in DevicesCubit to fetch devices by room ID and updated
related classes and API calls to support this functionality.
This commit is contained in:
Mohammad Salameh
2024-04-02 12:12:54 +03:00
parent 1397778123
commit 5dc4f96a71
8 changed files with 75 additions and 26 deletions
+11 -4
View File
@@ -1,30 +1,37 @@
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
class RoomModel {
final int? id;
final String? name;
final List<DevicesCategoryModel>? categories;
List<DeviceModel>? devices;
RoomModel({
required this.id,
required this.name,
required this.categories,
required this.devices,
});
Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
'devices': categories,
'devices': devices,
};
}
factory RoomModel.fromJson(Map<String, dynamic> json) {
List<DeviceModel> devices = [];
if (json['devices'] != null) {
for (var device in json['devices']) {
devices.add(DeviceModel.fromJson(device));
}
}
return RoomModel(
id: json['roomId'],
name: json['roomName'],
categories: json['devices'],
devices: devices,
);
}
}