mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 01:44:55 +00:00
Implemented home management and user invitation flows
This commit is contained in:
40
lib/services/api/home_management_api.dart
Normal file
40
lib/services/api/home_management_api.dart
Normal file
@ -0,0 +1,40 @@
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:syncrow_app/features/auth/model/user_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
||||
import 'package:syncrow_app/services/api/http_service.dart';
|
||||
|
||||
class HomeManagementAPI {
|
||||
static final HTTPService _httpService = HTTPService();
|
||||
|
||||
static Future<List<DeviceModel>> fetchDevicesByUserId() async {
|
||||
var storage = const FlutterSecureStorage();
|
||||
var userId = await storage.read(key: UserModel.userUuidKey) ?? '';
|
||||
|
||||
List<DeviceModel> list = [];
|
||||
await _httpService.get(
|
||||
path: ApiEndpoints.getDevicesByUserId.replaceAll("{userId}", userId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
json.forEach((value) {
|
||||
list.add(DeviceModel.fromJson(value));
|
||||
});
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> assignDeviceToRoom(Map<String, String> body) async {
|
||||
try {
|
||||
final response = await _httpService.put(
|
||||
path: ApiEndpoints.assignDeviceToRoom,
|
||||
body: body,
|
||||
expectedResponseModel: (json) {
|
||||
return json;
|
||||
},
|
||||
);
|
||||
return response;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user