mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-10 23:27:22 +00:00
fixed space
This commit is contained in:
@ -1,32 +1,47 @@
|
||||
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/features/devices/model/subspace_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<SpaceModel>> getSpacesByUserId() async {
|
||||
try {
|
||||
var uuid =
|
||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||
if (uuid == null) throw Exception("User UUID is missing");
|
||||
|
||||
final path = ApiEndpoints.userSpaces.replaceFirst('{userUuid}', uuid);
|
||||
final response = await _httpService.get(
|
||||
path: path,
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) => SpaceModel.fromJsonList(json['data']),
|
||||
);
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
print("Error in getSpacesByUserId: $error");
|
||||
rethrow; // Rethrow the error to be caught by `fetchUnitsByUserId`
|
||||
}
|
||||
}
|
||||
|
||||
static Future<List<RoomModel>> getRoomsBySpaceId(String unitId) async {
|
||||
static Future<List<SubSpaceModel>> getSubSpaceBySpaceId(
|
||||
String communityId, String spaceId) async {
|
||||
final path = ApiEndpoints.listSubspace
|
||||
.replaceFirst('{communityUuid}', communityId)
|
||||
.replaceFirst('{spaceUuid}', spaceId);
|
||||
|
||||
final response = await _httpService.get(
|
||||
path: "${ApiEndpoints.unitChild}$unitId",
|
||||
path: path,
|
||||
queryParameters: {"page": 1, "pageSize": 10},
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
List<RoomModel> rooms = [];
|
||||
List<SubSpaceModel> rooms = [];
|
||||
for (var room in json['children']) {
|
||||
rooms.add(RoomModel.fromJson(room));
|
||||
rooms.add(SubSpaceModel.fromJson(room));
|
||||
}
|
||||
return rooms;
|
||||
},
|
||||
|
Reference in New Issue
Block a user