Refactor code by adding new API endpoint for assigning a device to a room and removing redundant code in device management settings.

This commit is contained in:
mohammad
2025-06-02 12:52:48 +03:00
parent a44d4231f1
commit cf5e05a888
11 changed files with 620 additions and 230 deletions

View File

@ -0,0 +1,183 @@
class DeviceInfoModel {
final int activeTime;
final String category;
final String categoryName;
final int createTime;
final String gatewayId;
final String icon;
final String ip;
final String lat;
final String localKey;
final String lon;
final String model;
final String name;
final String nodeId;
final bool online;
final String ownerId;
final String productName;
final bool sub;
final String timeZone;
final int updateTime;
final String uuid;
final String productUuid;
final String productType;
final String permissionType;
final String macAddress;
final Subspace subspace;
DeviceInfoModel({
required this.activeTime,
required this.category,
required this.categoryName,
required this.createTime,
required this.gatewayId,
required this.icon,
required this.ip,
required this.lat,
required this.localKey,
required this.lon,
required this.model,
required this.name,
required this.nodeId,
required this.online,
required this.ownerId,
required this.productName,
required this.sub,
required this.timeZone,
required this.updateTime,
required this.uuid,
required this.productUuid,
required this.productType,
required this.permissionType,
required this.macAddress,
required this.subspace,
});
factory DeviceInfoModel.fromJson(Map<String, dynamic> json) {
return DeviceInfoModel(
activeTime: json['activeTime'] as int? ?? 0,
category: json['category'] ?? '',
categoryName: json['categoryName'] as String? ?? '',
createTime: json['createTime'] as int? ?? 0,
gatewayId: json['gatewayId'] as String? ?? '',
icon: json['icon'] as String? ?? '',
ip: json['ip'] as String? ?? '',
lat: json['lat'] as String? ?? '',
localKey: json['localKey'] as String? ?? '',
lon: json['lon'] as String? ?? '',
model: json['model'] as String? ?? '',
name: json['name'] as String? ?? '',
nodeId: json['nodeId'] as String? ?? '',
online: json['online'] as bool? ?? false,
ownerId: json['ownerId'] as String? ?? '',
productName: json['productName'] as String? ?? '',
sub: json['sub'] as bool? ?? false,
timeZone: json['timeZone'] as String? ?? '',
updateTime: json['updateTime'] as int? ?? 0,
uuid: json['uuid'] as String? ?? '',
productUuid: json['productUuid'] as String? ?? '',
productType: json['productType'] as String? ?? '',
permissionType: json['permissionType'] as String? ?? '',
macAddress: json['macAddress'] as String? ?? '',
subspace:
Subspace.fromJson(json['subspace'] as Map<String, dynamic>? ?? {}),
);
}
Map<String, dynamic> toJson() {
return {
'activeTime': activeTime,
'category': category,
'categoryName': categoryName,
'createTime': createTime,
'gatewayId': gatewayId,
'icon': icon,
'ip': ip,
'lat': lat,
'localKey': localKey,
'lon': lon,
'model': model,
'name': name,
'nodeId': nodeId,
'online': online,
'ownerId': ownerId,
'productName': productName,
'sub': sub,
'timeZone': timeZone,
'updateTime': updateTime,
'uuid': uuid,
'productUuid': productUuid,
'productType': productType,
'permissionType': permissionType,
'macAddress': macAddress,
'subspace': subspace.toJson(),
};
}
static DeviceInfoModel empty() {
return DeviceInfoModel(
activeTime: 0,
category: '',
categoryName: '',
createTime: 0,
gatewayId: '',
icon: '',
ip: '',
lat: '',
localKey: '',
lon: '',
model: '',
name: '',
nodeId: '',
online: false,
ownerId: '',
productName: '',
sub: false,
timeZone: '',
updateTime: 0,
uuid: '',
productUuid: '',
productType: '',
permissionType: '',
macAddress: '',
subspace: Subspace(
uuid: '',
createdAt: '',
updatedAt: '',
subspaceName: '',
),
);
}
}
class Subspace {
final String uuid;
final String createdAt;
final String updatedAt;
final String subspaceName;
Subspace({
required this.uuid,
required this.createdAt,
required this.updatedAt,
required this.subspaceName,
});
factory Subspace.fromJson(Map<String, dynamic> json) {
return Subspace(
uuid: json['uuid'] as String? ?? '',
createdAt: json['createdAt'] as String? ?? '',
updatedAt: json['updatedAt'] as String? ?? '',
subspaceName: json['subspaceName'] as String? ?? '',
);
}
Map<String, dynamic> toJson() {
return {
'uuid': uuid,
'createdAt': createdAt,
'updatedAt': updatedAt,
'subspaceName': subspaceName,
};
}
}

View File

@ -0,0 +1,35 @@
import 'package:syncrow_web/pages/visitor_password/model/device_model.dart';
class SubSpaceModel {
final String? id;
final String? name;
List<DeviceModel>? devices;
SubSpaceModel({
required this.id,
required this.name,
required this.devices,
});
Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
'devices': devices?.map((device) => device.toJson()).toList(),
};
}
factory SubSpaceModel.fromJson(Map<String, dynamic> json) {
List<DeviceModel> devices = [];
if (json['devices'] != null) {
for (var device in json['devices']) {
devices.add(DeviceModel.fromJson(device));
}
}
return SubSpaceModel(
id: json['uuid'] as String? ?? '',
name: json['subspaceName'] as String? ?? '',
devices: devices.isNotEmpty ? devices : null as List<DeviceModel>?,
);
}
}