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
@@ -16,6 +16,7 @@ abstract class ApiEndpoints {
// Devices
static const String control = '$baseUrl/device/control';
static const String devicesByRoom = '$baseUrl/device/room';
//groups
static const String groups = '$baseUrl/group';
-3
View File
@@ -37,9 +37,6 @@ class HTTPService {
path,
queryParameters: queryParameters,
);
// debugPrint("status code is ${response.statusCode}");
// debugPrint("response data is ${response.data}");
return expectedResponseModel(response.data);
} catch (error) {
debugPrint("******* Error");
+18 -1
View File
@@ -1,6 +1,7 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
import 'package:syncrow_app/features/auth/model/user_model.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/model/room_model.dart';
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
import 'package:syncrow_app/services/api/http_service.dart';
@@ -23,7 +24,7 @@ class SpacesAPI {
}
//get rooms by space id
static Future<List<RoomModel>> getRooms(int spaceId) async {
static Future<List<RoomModel>> getRoomsBySpaceId(int spaceId) async {
final response = await _httpService.get(
path: ApiEndpoints.rooms,
queryParameters: {"homeId": spaceId},
@@ -38,4 +39,20 @@ class SpacesAPI {
);
return response;
}
static Future<List<DeviceModel>> getDevicesByRoomId(int roomId) async {
final response = await _httpService.get(
path: ApiEndpoints.devicesByRoom,
queryParameters: {"roomId": roomId, "pageSize": 10},
showServerMessage: false,
expectedResponseModel: (json) {
List<DeviceModel> devices = [];
for (var device in json['devices']) {
devices.add(DeviceModel.fromJson(device));
}
return devices;
},
);
return response;
}
}