mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 17:47:28 +00:00

Added a new method in DevicesCubit to fetch devices by room ID and updated related classes and API calls to support this functionality.
59 lines
1.9 KiB
Dart
59 lines
1.9 KiB
Dart
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';
|
|
|
|
class SpacesAPI {
|
|
static final HTTPService _httpService = HTTPService();
|
|
|
|
static Future<List<SpaceModel>> getSpaces() async {
|
|
var uuid =
|
|
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
|
final response = await _httpService.get(
|
|
path: ApiEndpoints.spaces,
|
|
queryParameters: {
|
|
"userUuid": uuid,
|
|
},
|
|
showServerMessage: false,
|
|
expectedResponseModel: (json) => SpaceModel.fromJsonList(json),
|
|
);
|
|
return response;
|
|
}
|
|
|
|
//get rooms by space id
|
|
static Future<List<RoomModel>> getRoomsBySpaceId(int spaceId) async {
|
|
final response = await _httpService.get(
|
|
path: ApiEndpoints.rooms,
|
|
queryParameters: {"homeId": spaceId},
|
|
showServerMessage: false,
|
|
expectedResponseModel: (json) {
|
|
List<RoomModel> rooms = [];
|
|
for (var room in json) {
|
|
rooms.add(RoomModel.fromJson(room));
|
|
}
|
|
return rooms;
|
|
},
|
|
);
|
|
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;
|
|
}
|
|
}
|