push automation details and update automation

This commit is contained in:
ashrafzarkanisala
2024-07-25 00:25:48 +03:00
parent 56024ba3a3
commit 8a4c5af2e7
23 changed files with 1271 additions and 709 deletions

View File

@ -8,6 +8,7 @@ import 'package:syncrow_app/services/api/http_service.dart';
class SceneApi {
static final HTTPService _httpService = HTTPService();
//create scene
static Future<Map<String, dynamic>> createScene(
CreateSceneModel createSceneModel) async {
try {
@ -25,6 +26,7 @@ class SceneApi {
}
}
// create automation
static Future<Map<String, dynamic>> createAutomation(
CreateAutomationModel createAutomationModel) async {
try {
@ -42,6 +44,8 @@ class SceneApi {
}
}
//get scene by unit id
static Future<List<ScenesModel>> getScenesByUnitId(String unitId) async {
try {
final response = await _httpService.get(
@ -61,6 +65,27 @@ class SceneApi {
}
}
//getAutomation
static Future<List<ScenesModel>> getAutomationByUnitId(String unitId) async {
try {
final response = await _httpService.get(
path: ApiEndpoints.getUnitAutomation.replaceAll('{unitUuid}', unitId),
showServerMessage: false,
expectedResponseModel: (json) {
List<ScenesModel> scenes = [];
for (var scene in json) {
scenes.add(ScenesModel.fromJson(scene));
}
return scenes;
},
);
return response;
} catch (e) {
rethrow;
}
}
static Future<bool> triggerScene(String sceneId) async {
try {
final response = await _httpService.post(
@ -74,6 +99,22 @@ class SceneApi {
}
}
//automation details
static Future<SceneDetailsModel> getAutomationDetails(
String automationId) async {
try {
final response = await _httpService.get(
path: ApiEndpoints.getAutomationDetails
.replaceAll('{automationId}', automationId),
showServerMessage: false,
expectedResponseModel: (json) => SceneDetailsModel.fromJson(json),
);
return response;
} catch (e) {
rethrow;
}
}
//getScene
static Future<SceneDetailsModel> getSceneDetails(String sceneId) async {
@ -89,7 +130,7 @@ class SceneApi {
}
}
//updateScene
//update Scene
static updateScene(CreateSceneModel createSceneModel, String sceneId) async {
try {
final response = await _httpService.put(
@ -106,7 +147,26 @@ class SceneApi {
}
}
//deleteScene
//update automation
static updateAutomation(
CreateAutomationModel createAutomationModel, String automationId) async {
try {
final response = await _httpService.put(
path: ApiEndpoints.updateAutomation
.replaceAll('{automationId}', automationId),
body: createAutomationModel
.toJson(automationId.isNotEmpty == true ? automationId : null),
expectedResponseModel: (json) {
return json;
},
);
return response;
} catch (e) {
rethrow;
}
}
//delete Scene
static Future<bool> deleteScene(
{required String unitUuid, required String sceneId}) async {