mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-08-26 09:49:40 +00:00
all_devices and Restrict_user
This commit is contained in:
@ -225,7 +225,7 @@ abstract class ApiEndpoints {
|
||||
static const String getDeviceLogs = '/device/report-logs/{uuid}?code={code}';
|
||||
static const String terms = '/terms';
|
||||
static const String policy = '/policy';
|
||||
static const String getPermission = '/permission/{roleUuid}';
|
||||
|
||||
///permission/roleUuid
|
||||
static const String getPermission = '/permission/{roleUuid}';
|
||||
static const String getAllDevices =
|
||||
'/projects/{projectUuid}/communities/{communityUuid}/spaces/{spaceUuid}/devices';
|
||||
}
|
||||
|
@ -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>[];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user