Updated the API Endpoints, API Calls, Data Models and cubits to the lateset changes from the backend

This commit is contained in:
Mohammad Salameh
2024-04-29 10:00:58 +03:00
parent f24953a57c
commit f8358a0877
19 changed files with 255 additions and 199 deletions

View File

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
@ -11,7 +13,7 @@ class DevicesAPI {
DeviceControlModel controlModel) async {
try {
final response = await _httpService.post(
path: ApiEndpoints.control,
path: ApiEndpoints.controlDevice,
body: controlModel.toJson(),
showServerMessage: false,
expectedResponseModel: (json) {
@ -24,7 +26,7 @@ class DevicesAPI {
}
}
static Future<List<DevicesCategoryModel>> fetchGroups(int spaceId) async {
static Future<List<DevicesCategoryModel>> fetchGroups(String spaceId) async {
Map<String, dynamic> params = {
"homeId": spaceId,
"pageSize": 100,
@ -32,7 +34,7 @@ class DevicesAPI {
};
final response = await _httpService.get(
path: ApiEndpoints.groups,
path: ApiEndpoints.groupBySpace.replaceAll("{spaceUuid}", spaceId),
queryParameters: params,
showServerMessage: false,
expectedResponseModel: (json) =>
@ -43,7 +45,8 @@ class DevicesAPI {
static Future<Map<String, dynamic>> getDeviceStatus(String deviceId) async {
final response = await _httpService.get(
path: '${ApiEndpoints.deviceStatus}/$deviceId/functions/status',
path: ApiEndpoints.deviceFunctionsStatus
.replaceAll('{deviceUuid}', deviceId),
showServerMessage: false,
expectedResponseModel: (json) {
return json;
@ -52,14 +55,20 @@ class DevicesAPI {
return response;
}
static Future<List<DeviceModel>> getDevicesByRoomId(int roomId) async {
static Future<List<DeviceModel>> getDevicesByRoomId(String roomId) async {
// print("Room ID: $roomId");
final response = await _httpService.get(
path: ApiEndpoints.devicesByRoom,
queryParameters: {"roomId": roomId, "pageSize": 10},
path: ApiEndpoints.deviceByRoom,
queryParameters: {"roomUuid": roomId},
showServerMessage: false,
expectedResponseModel: (json) {
if (json == null || json.isEmpty || json == []) {
print('json: $json');
return <DeviceModel>[];
}
print('json: $json');
List<DeviceModel> devices = [];
for (var device in json['devices']) {
for (var device in json) {
devices.add(DeviceModel.fromJson(device));
}
return devices;