mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 01:35:23 +00:00
38 lines
1.3 KiB
Dart
38 lines
1.3 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/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>> getUnitsByUserId() async {
|
|
var uuid =
|
|
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
|
final response = await _httpService.get(
|
|
path: "${ApiEndpoints.unitUser}$uuid",
|
|
showServerMessage: false,
|
|
expectedResponseModel: (json) => SpaceModel.fromJsonList(json),
|
|
);
|
|
return response;
|
|
}
|
|
|
|
static Future<List<RoomModel>> getRoomsBySpaceId(String unitId) async {
|
|
final response = await _httpService.get(
|
|
path: "${ApiEndpoints.unitChild}$unitId",
|
|
queryParameters: {"page": 1, "pageSize": 10},
|
|
showServerMessage: false,
|
|
expectedResponseModel: (json) {
|
|
List<RoomModel> rooms = [];
|
|
for (var room in json['children']) {
|
|
rooms.add(RoomModel.fromJson(room));
|
|
}
|
|
return rooms;
|
|
},
|
|
);
|
|
return response;
|
|
}
|
|
}
|