diff --git a/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart b/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart index 801daa1c..767f40b2 100644 --- a/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart +++ b/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart @@ -324,6 +324,8 @@ class RoutineBloc extends Bloc { Future _onCreateAutomation(CreateAutomationEvent event, Emitter emit) async { try { + final projectUuid = await ProjectManager.getProjectUUID() ?? ''; + if (state.routineName == null || state.routineName!.isEmpty) { emit(state.copyWith( errorMessage: 'Automation name is required', @@ -434,7 +436,7 @@ class RoutineBloc extends Bloc { actions: actions, ); - final result = await SceneApi.createAutomation(createAutomationModel); + final result = await SceneApi.createAutomation(createAutomationModel, projectUuid); if (result['success']) { add(ResetRoutineState()); add(const LoadAutomation()); diff --git a/lib/services/routines_api.dart b/lib/services/routines_api.dart index ea01a5b7..fbc6c9ec 100644 --- a/lib/services/routines_api.dart +++ b/lib/services/routines_api.dart @@ -33,10 +33,10 @@ class SceneApi { // // create automation static Future> createAutomation( - CreateAutomationModel createAutomationModel) async { + CreateAutomationModel createAutomationModel, String projectId) async { try { final response = await _httpService.post( - path: ApiEndpoints.createAutomation, + path: ApiEndpoints.createAutomation.replaceAll('{projectId}', projectId), body: createAutomationModel.toMap(), showServerMessage: false, expectedResponseModel: (json) { diff --git a/lib/utils/constants/api_const.dart b/lib/utils/constants/api_const.dart index 4307699e..b30b02e3 100644 --- a/lib/utils/constants/api_const.dart +++ b/lib/utils/constants/api_const.dart @@ -69,10 +69,10 @@ 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 = '/automation'; + static const String createAutomation = '/projects/{projectId}/automations'; static const String getUnitScenes = '/projects/{projectId}/communities/{communityUuid}/spaces/{spaceUuid}/scenes'; static const String getAutomationDetails = '/automation/details/{automationId}';