diff --git a/lib/features/app_layout/bloc/home_cubit.dart b/lib/features/app_layout/bloc/home_cubit.dart index 816b64d..e4dde3e 100644 --- a/lib/features/app_layout/bloc/home_cubit.dart +++ b/lib/features/app_layout/bloc/home_cubit.dart @@ -274,15 +274,11 @@ class HomeCubit extends Cubit { } fetchRoomsByUnitId(SpaceModel space) async { - print("Community ID: ${space.community.uuid}"); - print("Space ID: ${space.id}"); - emitSafe(GetSpaceRoomsLoading()); try { space.subspaces = await SpacesAPI.getSubSpaceBySpaceId(space.community.uuid, space.id); } catch (failure) { - print("Error fetching subspaces: $failure"); emitSafe(GetSpaceRoomsError(failure.toString())); return; diff --git a/lib/features/devices/model/subspace_model.dart b/lib/features/devices/model/subspace_model.dart index b2aa133..f8be0aa 100644 --- a/lib/features/devices/model/subspace_model.dart +++ b/lib/features/devices/model/subspace_model.dart @@ -15,7 +15,7 @@ class SubSpaceModel { return { 'id': id, 'name': name, - 'devices': devices, + 'devices': devices?.map((device) => device.toJson()).toList(), }; } @@ -28,8 +28,8 @@ class SubSpaceModel { } return SubSpaceModel( id: json['uuid'], - name: json['name'], - devices: [], + name: json['subspaceName'], + devices: devices, ); } } diff --git a/lib/services/api/spaces_api.dart b/lib/services/api/spaces_api.dart index 1565d3b..15122cb 100644 --- a/lib/services/api/spaces_api.dart +++ b/lib/services/api/spaces_api.dart @@ -31,24 +31,35 @@ class SpacesAPI { static Future> getSubSpaceBySpaceId( String communityId, String spaceId) async { - final path = ApiEndpoints.listSubspace - .replaceFirst('{communityUuid}', communityId) - .replaceFirst('{spaceUuid}', spaceId); - print("Constructed path: $path"); + try { + // Construct the API path + final path = ApiEndpoints.listSubspace + .replaceFirst('{communityUuid}', communityId) + .replaceFirst('{spaceUuid}', spaceId); - final response = await _httpService.get( - path: path, - queryParameters: {"page": 1, "pageSize": 10}, - showServerMessage: false, - expectedResponseModel: (json) { - List rooms = []; - for (var room in json['children']) { - rooms.add(SubSpaceModel.fromJson(room)); - } - return rooms; - }, - ); - return response; + + final response = await _httpService.get( + path: path, + queryParameters: {"page": 1, "pageSize": 10}, + showServerMessage: false, + expectedResponseModel: (json) { + + List rooms = []; + if (json['data'] != null) { + for (var subspace in json['data']) { + rooms.add(SubSpaceModel.fromJson(subspace)); + } + } else { + print("Warning: 'data' key is missing or null in response JSON."); + } + return rooms; + }, + ); + + return response; + } catch (error, stackTrace) { + return []; // Return an empty list if there's an error + } } static Future generateInvitationCode(