From e0486deecb4510c242172f85ec3861a5665dcda9 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Fri, 14 Mar 2025 12:16:32 +0400 Subject: [PATCH] changed endpoint for automation update --- lib/pages/routines/bloc/routine_bloc/routine_bloc.dart | 10 +++++++--- lib/services/routines_api.dart | 7 +++++-- lib/utils/constants/api_const.dart | 5 +++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart b/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart index b7e75847..361810c0 100644 --- a/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart +++ b/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart @@ -808,7 +808,9 @@ class RoutineBloc extends Bloc { unitUuid: spaceBloc.state.selectedSpaces[0], sceneId: state.sceneId ?? ''); } else { await SceneApi.deleteAutomation( - unitUuid: spaceBloc.state.selectedSpaces[0], automationId: state.automationId ?? '',projectId: projectId); + unitUuid: spaceBloc.state.selectedSpaces[0], + automationId: state.automationId ?? '', + projectId: projectId); } add(const LoadScenes()); @@ -948,6 +950,8 @@ class RoutineBloc extends Bloc { FutureOr _onUpdateAutomation(UpdateAutomation event, Emitter emit) async { try { + final projectId = await ProjectManager.getProjectUUID() ?? ''; + if (state.routineName == null || state.routineName!.isEmpty) { emit(state.copyWith( errorMessage: 'Automation name is required', @@ -1057,8 +1061,8 @@ class RoutineBloc extends Bloc { actions: actions, ); - final result = - await SceneApi.updateAutomation(createAutomationModel, state.automationId ?? ''); + final result = await SceneApi.updateAutomation( + createAutomationModel, state.automationId ?? '', projectId); if (result['success']) { add(ResetRoutineState()); diff --git a/lib/services/routines_api.dart b/lib/services/routines_api.dart index c2593b4d..56a29aa1 100644 --- a/lib/services/routines_api.dart +++ b/lib/services/routines_api.dart @@ -166,10 +166,13 @@ class SceneApi { } //update automation - static updateAutomation(CreateAutomationModel createAutomationModel, String automationId) async { + static updateAutomation( + CreateAutomationModel createAutomationModel, String automationId, String projectId) async { try { final response = await _httpService.put( - path: ApiEndpoints.updateAutomation.replaceAll('{automationId}', automationId), + path: ApiEndpoints.updateAutomation + .replaceAll('{automationId}', automationId) + .replaceAll('{projectId}', projectId), body: createAutomationModel.toJson(automationId.isNotEmpty == true ? automationId : null), expectedResponseModel: (json) { return json; diff --git a/lib/utils/constants/api_const.dart b/lib/utils/constants/api_const.dart index 5a42cb47..71e0fc55 100644 --- a/lib/utils/constants/api_const.dart +++ b/lib/utils/constants/api_const.dart @@ -69,7 +69,8 @@ abstract class ApiEndpoints { //product static const String listProducts = '/products'; static const String getSpaceScenes = '/scene/tap-to-run/{spaceUuid}'; - static const String getSpaceAutomation = '/projects/{projectId}/communities/{communityId}/spaces/{spaceUuid}/automations'; + static const String getSpaceAutomation = + '/projects/{projectId}/communities/{communityId}/spaces/{spaceUuid}/automations'; static const String getIconScene = '/scene/icon'; static const String createScene = '/scene/tap-to-run'; static const String createAutomation = '/projects/{projectId}/automations'; @@ -82,7 +83,7 @@ abstract class ApiEndpoints { static const String deleteAutomation = '/projects/{projectId}/automations/{automationId}'; static const String updateScene = '/scene/tap-to-run/{sceneId}'; - static const String updateAutomation = '/automation/{automationId}'; + static const String updateAutomation = '/projects/{projectId}/automations/{automationId}'; //space model static const String listSpaceModels = '/projects/{projectId}/space-models';