mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 04:47:54 +00:00
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:
@@ -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';
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user