mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 01:56:19 +00:00
Updated the API Endpoints, API Calls, Data Models and cubits to the lateset changes from the backend
This commit is contained in:
@ -18,9 +18,9 @@ part 'home_state.dart';
|
||||
class HomeCubit extends Cubit<HomeState> {
|
||||
HomeCubit._() : super(HomeInitial()) {
|
||||
if (selectedSpace == null) {
|
||||
fetchSpaces().then((value) {
|
||||
fetchUnitsByUserId().then((value) {
|
||||
if (selectedSpace != null) {
|
||||
fetchRooms(selectedSpace!);
|
||||
fetchRoomsByUnitId(selectedSpace!);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -120,10 +120,10 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
}
|
||||
|
||||
//////////////////////////////////////// API ////////////////////////////////////////
|
||||
fetchSpaces() async {
|
||||
fetchUnitsByUserId() async {
|
||||
emitSafe(GetSpacesLoading());
|
||||
try {
|
||||
spaces = await SpacesAPI.getSpaces();
|
||||
spaces = await SpacesAPI.getUnitsByUserId();
|
||||
} catch (failure) {
|
||||
emitSafe(GetSpacesError(failure.toString()));
|
||||
return;
|
||||
@ -132,13 +132,13 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
if (spaces != null && spaces!.isNotEmpty) {
|
||||
selectedSpace = spaces!.first;
|
||||
emitSafe(GetSpacesSuccess(spaces!));
|
||||
fetchRooms(selectedSpace!);
|
||||
// fetchRoomsByUnitId(selectedSpace!);
|
||||
} else {
|
||||
emitSafe(GetSpacesError("No spaces found"));
|
||||
}
|
||||
}
|
||||
|
||||
fetchRooms(SpaceModel space) async {
|
||||
fetchRoomsByUnitId(SpaceModel space) async {
|
||||
emitSafe(GetSpaceRoomsLoading());
|
||||
try {
|
||||
space.rooms = await SpacesAPI.getRoomsBySpaceId(space.id!);
|
||||
|
@ -1,11 +1,14 @@
|
||||
import 'package:syncrow_app/features/devices/model/room_model.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
class SpaceModel {
|
||||
final int? id;
|
||||
final String? id;
|
||||
final String? name;
|
||||
final SpaceType type;
|
||||
late List<RoomModel>? rooms;
|
||||
|
||||
SpaceModel({
|
||||
required this.type,
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.rooms,
|
||||
@ -21,8 +24,9 @@ class SpaceModel {
|
||||
|
||||
factory SpaceModel.fromJson(Map<String, dynamic> json) {
|
||||
return SpaceModel(
|
||||
id: int.parse(json['homeId']),
|
||||
name: json['homeName'],
|
||||
id: json['uuid'],
|
||||
name: json['name'],
|
||||
type: spaceTypesMap[json['type']]!,
|
||||
rooms: [],
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user