mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-24 22:47:56 +00:00
added unit devices
This commit is contained in:
@@ -55,7 +55,8 @@ abstract class ApiEndpoints {
|
||||
static const String addUnitToUser = '/unit/user';
|
||||
//GET
|
||||
static const String unitByUuid = '/unit/';
|
||||
static const String listSubspace = '/communities/{communityUuid}/spaces/{spaceUuid}/subspaces';
|
||||
static const String listSubspace =
|
||||
'/communities/{communityUuid}/spaces/{spaceUuid}/subspaces';
|
||||
static const String unitParent = '/unit/parent/{unitUuid}';
|
||||
static const String unitUser = '/unit/user/';
|
||||
static const String invitationCode = '/unit/{unitUuid}/invitation-code';
|
||||
@@ -75,10 +76,11 @@ abstract class ApiEndpoints {
|
||||
//PUT
|
||||
static const String renameRoom = '/room/{roomUuid}';
|
||||
|
||||
|
||||
//SPACE Module
|
||||
//GET
|
||||
static const String userSpaces = '/user/{userUuid}/spaces';
|
||||
static const String spaceDevices =
|
||||
'/communities/{communityUuid}/spaces/{spaceUuid}/devices';
|
||||
|
||||
///Group Module
|
||||
//POST
|
||||
@@ -106,7 +108,8 @@ abstract class ApiEndpoints {
|
||||
static const String openDoorLock = '/door-lock/open/{doorLockUuid}';
|
||||
|
||||
//GET
|
||||
static const String deviceByRoom = '/device/room';
|
||||
static const String deviceByRoom =
|
||||
'/communities/:communityUuid/spaces/:spaceUuid/subspaces/:subSpaceUuid/devices';
|
||||
static const String deviceByUuid = '/device/{deviceUuid}';
|
||||
static const String deviceFunctions = '/device/{deviceUuid}/functions';
|
||||
static const String gatewayApi = '/device/gateway/{gatewayUuid}/devices';
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -28,15 +28,38 @@ class HomeManagementAPI {
|
||||
|
||||
static Future<List<DeviceModel>> fetchDevicesByUnitId() async {
|
||||
List<DeviceModel> list = [];
|
||||
await _httpService.get(
|
||||
path: ApiEndpoints.getDevicesByUnitId.replaceAll(
|
||||
"{unitUuid}", HomeCubit.getInstance().selectedSpace?.id ?? ''),
|
||||
|
||||
try {
|
||||
// Retrieve selected space details
|
||||
final selectedSpace = HomeCubit.getInstance().selectedSpace;
|
||||
final communityUuid = selectedSpace?.community?.uuid ?? '';
|
||||
final spaceUuid = selectedSpace?.id ?? '';
|
||||
|
||||
// Ensure both placeholders are replaced
|
||||
final path = ApiEndpoints.spaceDevices
|
||||
.replaceAll("{communityUuid}", communityUuid)
|
||||
.replaceAll("{spaceUuid}", spaceUuid);
|
||||
|
||||
// Debugging: Log the path
|
||||
print("Fetching devices with path: $path");
|
||||
|
||||
await _httpService.get(
|
||||
path: path,
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
json.forEach((value) {
|
||||
list.add(DeviceModel.fromJson(value));
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
// Debugging: Log successful fetch
|
||||
print("Successfully fetched ${list.length} devices.");
|
||||
} catch (e) {
|
||||
// Log the error for debugging
|
||||
print("Error fetching devices for the unit: $e");
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user