mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 05:37:55 +00:00
getting spaces and rooms from api {null checks}
This commit is contained in:
@@ -1,26 +1,19 @@
|
||||
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/bloc/auth_cubit.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 Future<Token> loginWithEmail(
|
||||
// {required LoginWithEmailModel model}) async {
|
||||
// final response = await HTTPService().post(
|
||||
// path: ApiEndpoints.login,
|
||||
// body: model.toJson(),
|
||||
// showServerMessage: false,
|
||||
// expectedResponseModel: (json) {
|
||||
// Token token = Token.fromJson(json['data']);
|
||||
// return token;
|
||||
// });
|
||||
// debugPrint("response: $response");
|
||||
// return response;
|
||||
// }
|
||||
|
||||
static Future<List<SpaceModel>> getSpaces() async {
|
||||
var uuid =
|
||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||
final response = await HTTPService().get(
|
||||
path: "${ApiEndpoints.spaces}/${AuthCubit.user!.uuid}",
|
||||
path: ApiEndpoints.spaces,
|
||||
queryParameters: {
|
||||
"userUuid": uuid,
|
||||
},
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
List<SpaceModel> spaces = [];
|
||||
@@ -32,4 +25,21 @@ class SpacesAPI {
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
//get rooms by space id
|
||||
static Future<List<RoomModel>> getRooms(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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user