From c2fc8fa0ae7c098d355e1245a23f2d1d65340456 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Fri, 14 Mar 2025 12:40:52 +0400 Subject: [PATCH 1/5] changed endpoint for create automation endpoint --- .../scene/bloc/create_scene/create_scene_bloc.dart | 8 +++++++- lib/services/api/api_links_endpoints.dart | 2 +- lib/services/api/scene_api.dart | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart index ac6072e..f364f88 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart @@ -1,6 +1,8 @@ import 'dart:async'; import 'package:equatable/equatable.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; +import 'package:syncrow_app/features/auth/model/project_model.dart'; import 'package:syncrow_app/features/devices/model/device_control_model.dart'; import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_bloc.dart'; import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_event.dart'; @@ -13,6 +15,7 @@ import 'package:syncrow_app/features/scene/model/icon_model.dart'; import 'package:syncrow_app/features/scene/model/scene_static_function.dart'; import 'package:syncrow_app/navigation/navigation_service.dart'; import 'package:syncrow_app/services/api/scene_api.dart'; +import 'package:syncrow_app/utils/constants/temp_const.dart'; import 'package:syncrow_app/utils/helpers/snack_bar.dart'; part 'create_scene_event.dart'; @@ -348,6 +351,8 @@ class CreateSceneBloc extends Bloc emit(CreateSceneLoading()); try { dynamic response; + Project? project = HomeCubit.getInstance().project; + if (event.createSceneModel != null) { response = event.updateScene ? await SceneApi.updateScene(event.createSceneModel!, event.sceneId) @@ -356,7 +361,8 @@ class CreateSceneBloc extends Bloc response = event.updateScene ? await SceneApi.updateAutomation( event.createAutomationModel!, event.sceneId) - : await SceneApi.createAutomation(event.createAutomationModel!); + : await SceneApi.createAutomation(event.createAutomationModel!, + project?.uuid ?? TempConst.projectIdDev); } if (response['success'] == true) { diff --git a/lib/services/api/api_links_endpoints.dart b/lib/services/api/api_links_endpoints.dart index 8710430..16010f7 100644 --- a/lib/services/api/api_links_endpoints.dart +++ b/lib/services/api/api_links_endpoints.dart @@ -144,7 +144,7 @@ abstract class ApiEndpoints { /// POST static const String createScene = '/scene/tap-to-run'; static const String triggerScene = '/scene/tap-to-run/{sceneId}/trigger'; - static const String createAutomation = '/automation'; + static const String createAutomation = '/projects/{projectId}/automations'; /// GET static const String getUnitScenes = diff --git a/lib/services/api/scene_api.dart b/lib/services/api/scene_api.dart index ce4a5ae..b08b936 100644 --- a/lib/services/api/scene_api.dart +++ b/lib/services/api/scene_api.dart @@ -6,7 +6,6 @@ import 'package:syncrow_app/features/scene/model/scenes_model.dart'; import 'package:syncrow_app/features/scene/model/update_automation.dart'; import 'package:syncrow_app/services/api/api_links_endpoints.dart'; import 'package:syncrow_app/services/api/http_service.dart'; -import 'package:syncrow_app/utils/constants/temp_const.dart'; class SceneApi { static final HTTPService _httpService = HTTPService(); @@ -31,10 +30,11 @@ 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) { From 067354874591c566a96bbacd677e87e28b79d971 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Fri, 14 Mar 2025 12:53:29 +0400 Subject: [PATCH 2/5] changed endpoint for getting automations by space --- .../scene/bloc/scene_bloc/scene_bloc.dart | 12 +++- .../scene/bloc/scene_bloc/scene_event.dart | 9 ++- lib/features/scene/view/scene_view.dart | 71 ++++++++++++------- .../scene/widgets/delete_routine_b.dart | 2 +- .../widgets/scene_view_widget/scene_item.dart | 4 ++ .../smart_enable_autoamtion.dart | 2 +- lib/services/api/api_links_endpoints.dart | 2 +- lib/services/api/scene_api.dart | 11 ++- 8 files changed, 77 insertions(+), 36 deletions(-) diff --git a/lib/features/scene/bloc/scene_bloc/scene_bloc.dart b/lib/features/scene/bloc/scene_bloc/scene_bloc.dart index 97b3ac6..3c21d60 100644 --- a/lib/features/scene/bloc/scene_bloc/scene_bloc.dart +++ b/lib/features/scene/bloc/scene_bloc/scene_bloc.dart @@ -46,8 +46,11 @@ class SceneBloc extends Bloc { emit(SceneLoading()); try { + Project? project = HomeCubit.getInstance().project; + if (event.unitId.isNotEmpty) { - automationList = await SceneApi.getAutomationByUnitId(event.unitId); + automationList = await SceneApi.getAutomationByUnitId( + event.unitId, event.communityId, project?.uuid ?? ''); emit(SceneLoaded(scenes, automationList)); } else { emit(const SceneError(message: 'Unit ID is empty')); @@ -96,11 +99,16 @@ class SceneBloc extends Bloc { )); try { + Project? project = HomeCubit.getInstance().project; + final success = await SceneApi.updateAutomationStatus( event.automationId, event.automationStatusUpdate); if (success) { automationList = await SceneApi.getAutomationByUnitId( - event.automationStatusUpdate.spaceUuid); + event.automationStatusUpdate.spaceUuid, + event.communityId, + project?.uuid ?? '' + ); newLoadingStates[event.automationId] = false; emit(SceneLoaded( currentState.scenes, diff --git a/lib/features/scene/bloc/scene_bloc/scene_event.dart b/lib/features/scene/bloc/scene_bloc/scene_event.dart index 7807bbb..513b020 100644 --- a/lib/features/scene/bloc/scene_bloc/scene_event.dart +++ b/lib/features/scene/bloc/scene_bloc/scene_event.dart @@ -22,11 +22,13 @@ class LoadScenes extends SceneEvent { class LoadAutomation extends SceneEvent { final String unitId; + final String communityId; - const LoadAutomation(this.unitId); + + const LoadAutomation(this.unitId, this.communityId); @override - List get props => [unitId]; + List get props => [unitId, communityId]; } class SceneTrigger extends SceneEvent { @@ -43,8 +45,9 @@ class SceneTrigger extends SceneEvent { class UpdateAutomationStatus extends SceneEvent { final String automationId; final AutomationStatusUpdate automationStatusUpdate; + final String communityId; - const UpdateAutomationStatus({required this.automationStatusUpdate, required this.automationId}); + const UpdateAutomationStatus({required this.automationStatusUpdate, required this.automationId, required this.communityId}); @override List get props => [automationStatusUpdate]; diff --git a/lib/features/scene/view/scene_view.dart b/lib/features/scene/view/scene_view.dart index 0994736..20140a9 100644 --- a/lib/features/scene/view/scene_view.dart +++ b/lib/features/scene/view/scene_view.dart @@ -49,7 +49,9 @@ class SceneView extends StatelessWidget { name: '', )), showInDevice: pageType)) - ..add(LoadAutomation(HomeCubit.getInstance().selectedSpace?.id ?? '')); + ..add(LoadAutomation( + HomeCubit.getInstance().selectedSpace?.id ?? '', + HomeCubit.getInstance().selectedSpace?.community.uuid ?? '')); } }, child: BlocBuilder( @@ -57,30 +59,37 @@ class SceneView extends StatelessWidget { if (state is DeleteSceneSuccess) { if (state.success) { BlocProvider.of(context).add(LoadScenes( - HomeCubit.getInstance().selectedSpace!.id, HomeCubit.getInstance().selectedSpace!, + HomeCubit.getInstance().selectedSpace!.id, + HomeCubit.getInstance().selectedSpace!, showInDevice: pageType)); - BlocProvider.of(context) - .add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id)); + BlocProvider.of(context).add(LoadAutomation( + HomeCubit.getInstance().selectedSpace!.id, + HomeCubit.getInstance().selectedSpace!.community.uuid)); } } if (state is CreateSceneWithTasks) { if (state.success == true) { BlocProvider.of(context).add(LoadScenes( - HomeCubit.getInstance().selectedSpace!.id, HomeCubit.getInstance().selectedSpace!, + HomeCubit.getInstance().selectedSpace!.id, + HomeCubit.getInstance().selectedSpace!, showInDevice: pageType)); - BlocProvider.of(context) - .add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id)); - context.read().add(const SmartSceneClearEvent()); + BlocProvider.of(context).add(LoadAutomation( + HomeCubit.getInstance().selectedSpace!.id, + HomeCubit.getInstance().selectedSpace!.community.uuid)); + context + .read() + .add(const SmartSceneClearEvent()); } } return BlocListener( listener: (context, state) { if (state is SceneTriggerSuccess) { context.showCustomSnackbar( - message: 'Scene ${state.sceneName} triggered successfully!'); + message: + 'Scene ${state.sceneName} triggered successfully!'); } }, - child: HomeCubit.getInstance().spaces?.isEmpty ?? true + child: HomeCubit.getInstance().spaces.isEmpty ? const CreateUnitWidget() : Column( mainAxisAlignment: MainAxisAlignment.start, @@ -114,25 +123,30 @@ class SceneView extends StatelessWidget { child: ListView( children: [ Theme( - data: ThemeData() - .copyWith(dividerColor: Colors.transparent), + data: ThemeData().copyWith( + dividerColor: Colors.transparent), child: ExpansionTile( - tilePadding: const EdgeInsets.symmetric(horizontal: 6), + tilePadding: + const EdgeInsets.symmetric( + horizontal: 6), initiallyExpanded: true, iconColor: ColorsManager.grayColor, - title: const BodyMedium(text: 'Tap to run routines'), + title: const BodyMedium( + text: 'Tap to run routines'), children: [ scenes.isNotEmpty ? SceneGrid( scenes: scenes, - loadingSceneId: state.loadingSceneId, + loadingSceneId: + state.loadingSceneId, disablePlayButton: false, - loadingStates: - state.loadingStates, // Add this line + loadingStates: state + .loadingStates, // Add this line ) : const Center( child: BodyMedium( - text: 'No scenes have been added yet', + text: + 'No scenes have been added yet', ), ), const SizedBox( @@ -142,25 +156,30 @@ class SceneView extends StatelessWidget { ), ), Theme( - data: ThemeData() - .copyWith(dividerColor: Colors.transparent), + data: ThemeData().copyWith( + dividerColor: Colors.transparent), child: ExpansionTile( initiallyExpanded: true, iconColor: ColorsManager.grayColor, - tilePadding: const EdgeInsets.symmetric(horizontal: 6), - title: const BodyMedium(text: 'Automation'), + tilePadding: + const EdgeInsets.symmetric( + horizontal: 6), + title: const BodyMedium( + text: 'Automation'), children: [ automationList.isNotEmpty ? SceneGrid( scenes: automationList, - loadingSceneId: state.loadingSceneId, + loadingSceneId: + state.loadingSceneId, disablePlayButton: true, - loadingStates: - state.loadingStates, // Add this line + loadingStates: state + .loadingStates, // Add this line ) : const Center( child: BodyMedium( - text: 'No automations have been added yet', + text: + 'No automations have been added yet', ), ), const SizedBox( diff --git a/lib/features/scene/widgets/delete_routine_b.dart b/lib/features/scene/widgets/delete_routine_b.dart index 888f80e..216eed2 100644 --- a/lib/features/scene/widgets/delete_routine_b.dart +++ b/lib/features/scene/widgets/delete_routine_b.dart @@ -25,7 +25,7 @@ class DeleteRoutineButton extends StatelessWidget { BlocProvider.of(context).add(LoadScenes( HomeCubit.getInstance().selectedSpace!.id, HomeCubit.getInstance().selectedSpace!)); BlocProvider.of(context) - .add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id)); + .add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id,HomeCubit.getInstance().selectedSpace!.community.uuid)); } } }, diff --git a/lib/features/scene/widgets/scene_view_widget/scene_item.dart b/lib/features/scene/widgets/scene_view_widget/scene_item.dart index 38edbbd..c41302d 100644 --- a/lib/features/scene/widgets/scene_view_widget/scene_item.dart +++ b/lib/features/scene/widgets/scene_view_widget/scene_item.dart @@ -132,6 +132,10 @@ class SceneItem extends StatelessWidget { spaceUuid: HomeCubit.getInstance() .selectedSpace! .id), + communityId: HomeCubit.getInstance() + .selectedSpace! + .community + .uuid, automationId: scene.id)); }, ), diff --git a/lib/features/scene/widgets/select_smart_scene/smart_enable_autoamtion.dart b/lib/features/scene/widgets/select_smart_scene/smart_enable_autoamtion.dart index 6560c63..200290c 100644 --- a/lib/features/scene/widgets/select_smart_scene/smart_enable_autoamtion.dart +++ b/lib/features/scene/widgets/select_smart_scene/smart_enable_autoamtion.dart @@ -22,7 +22,7 @@ class SmartEnableAutomation extends StatelessWidget { child: BlocBuilder( bloc: context.read() ..add( - LoadAutomation(HomeCubit.getInstance().selectedSpace?.id ?? '')), + LoadAutomation(HomeCubit.getInstance().selectedSpace?.id ?? '',HomeCubit.getInstance().selectedSpace?.community.uuid ?? '')), builder: (context, state) { if (state is SceneLoading) { return const Align( diff --git a/lib/services/api/api_links_endpoints.dart b/lib/services/api/api_links_endpoints.dart index 16010f7..c94151e 100644 --- a/lib/services/api/api_links_endpoints.dart +++ b/lib/services/api/api_links_endpoints.dart @@ -153,7 +153,7 @@ abstract class ApiEndpoints { static const String getScene = '/scene/tap-to-run/{sceneId}'; static const String getIconScene = '/scene/icon'; - static const String getUnitAutomation = '/automation/{unitUuid}'; + static const String getUnitAutomation = '/projects/{projectId}/communities/{communityId}/spaces/{unitUuid}/automations'; static const String getAutomationDetails = '/automation/details/{automationId}'; diff --git a/lib/services/api/scene_api.dart b/lib/services/api/scene_api.dart index b08b936..b21cf21 100644 --- a/lib/services/api/scene_api.dart +++ b/lib/services/api/scene_api.dart @@ -78,10 +78,17 @@ class SceneApi { //getAutomation - static Future> getAutomationByUnitId(String unitId) async { + static Future> getAutomationByUnitId( + String unitId, + String communityId, + String projectId, + ) async { try { final response = await _httpService.get( - path: ApiEndpoints.getUnitAutomation.replaceAll('{unitUuid}', unitId), + path: ApiEndpoints.getUnitAutomation + .replaceAll('{unitUuid}', unitId) + .replaceAll('{communityId}', communityId) + .replaceAll('{projectId}', projectId), showServerMessage: false, expectedResponseModel: (json) { List scenes = []; From 88aac86b102eeb919373c49f068a1f770691ef95 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Fri, 14 Mar 2025 12:55:33 +0400 Subject: [PATCH 3/5] updated endpoint for getting automation by id --- lib/features/scene/bloc/create_scene/create_scene_bloc.dart | 4 +++- lib/services/api/api_links_endpoints.dart | 2 +- lib/services/api/scene_api.dart | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart index f364f88..082fd69 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart @@ -427,6 +427,8 @@ class CreateSceneBloc extends Bloc emit(CreateSceneLoading()); try { + Project? project = HomeCubit.getInstance().project; + tasksList.clear(); tempTasksList.clear(); selectedValues.clear(); @@ -442,7 +444,7 @@ class CreateSceneBloc extends Bloc conditionRule = 'or'; final response = event.isAutomation - ? await SceneApi.getAutomationDetails(event.sceneId) + ? await SceneApi.getAutomationDetails(event.sceneId, project?.uuid ?? '') : await SceneApi.getSceneDetails(event.sceneId); if (response.id.isNotEmpty) { if (event.isAutomation) { diff --git a/lib/services/api/api_links_endpoints.dart b/lib/services/api/api_links_endpoints.dart index c94151e..fe271a3 100644 --- a/lib/services/api/api_links_endpoints.dart +++ b/lib/services/api/api_links_endpoints.dart @@ -156,7 +156,7 @@ abstract class ApiEndpoints { static const String getUnitAutomation = '/projects/{projectId}/communities/{communityId}/spaces/{unitUuid}/automations'; static const String getAutomationDetails = - '/automation/details/{automationId}'; + '/projects/{projectId}/automations/{automationId}'; /// PUT static const String updateScene = '/scene/tap-to-run/{sceneId}'; diff --git a/lib/services/api/scene_api.dart b/lib/services/api/scene_api.dart index b21cf21..b4397ac 100644 --- a/lib/services/api/scene_api.dart +++ b/lib/services/api/scene_api.dart @@ -119,11 +119,12 @@ class SceneApi { //automation details static Future getAutomationDetails( - String automationId) async { + String automationId, String projectId) async { try { final response = await _httpService.get( path: ApiEndpoints.getAutomationDetails - .replaceAll('{automationId}', automationId), + .replaceAll('{automationId}', automationId) + .replaceAll('{projectId}', projectId), showServerMessage: false, expectedResponseModel: (json) => SceneDetailsModel.fromJson(json), ); From 0d50aa68fabb06f92814e1090132fa8a0569e0ed Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Fri, 14 Mar 2025 12:58:12 +0400 Subject: [PATCH 4/5] updated endpoint for update automation --- .../scene/bloc/create_scene/create_scene_bloc.dart | 12 ++++++------ lib/services/api/api_links_endpoints.dart | 2 +- lib/services/api/scene_api.dart | 7 ++++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart index 082fd69..2ded3e5 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart @@ -15,7 +15,6 @@ import 'package:syncrow_app/features/scene/model/icon_model.dart'; import 'package:syncrow_app/features/scene/model/scene_static_function.dart'; import 'package:syncrow_app/navigation/navigation_service.dart'; import 'package:syncrow_app/services/api/scene_api.dart'; -import 'package:syncrow_app/utils/constants/temp_const.dart'; import 'package:syncrow_app/utils/helpers/snack_bar.dart'; part 'create_scene_event.dart'; @@ -359,10 +358,10 @@ class CreateSceneBloc extends Bloc : await SceneApi.createScene(event.createSceneModel!); } else if (event.createAutomationModel != null) { response = event.updateScene - ? await SceneApi.updateAutomation( - event.createAutomationModel!, event.sceneId) + ? await SceneApi.updateAutomation(event.createAutomationModel!, + event.sceneId, project?.uuid ?? '') : await SceneApi.createAutomation(event.createAutomationModel!, - project?.uuid ?? TempConst.projectIdDev); + project?.uuid ?? ''); } if (response['success'] == true) { @@ -427,7 +426,7 @@ class CreateSceneBloc extends Bloc emit(CreateSceneLoading()); try { - Project? project = HomeCubit.getInstance().project; + Project? project = HomeCubit.getInstance().project; tasksList.clear(); tempTasksList.clear(); @@ -444,7 +443,8 @@ class CreateSceneBloc extends Bloc conditionRule = 'or'; final response = event.isAutomation - ? await SceneApi.getAutomationDetails(event.sceneId, project?.uuid ?? '') + ? await SceneApi.getAutomationDetails( + event.sceneId, project?.uuid ?? '') : await SceneApi.getSceneDetails(event.sceneId); if (response.id.isNotEmpty) { if (event.isAutomation) { diff --git a/lib/services/api/api_links_endpoints.dart b/lib/services/api/api_links_endpoints.dart index fe271a3..78591f1 100644 --- a/lib/services/api/api_links_endpoints.dart +++ b/lib/services/api/api_links_endpoints.dart @@ -161,7 +161,7 @@ abstract class ApiEndpoints { /// PUT static const String updateScene = '/scene/tap-to-run/{sceneId}'; - static const String updateAutomation = '/automation/{automationId}'; + static const String updateAutomation = '/projects/{projectId}/automations/{automationId}'; static const String updateAutomationStatus = '/automation/status/{automationId}'; diff --git a/lib/services/api/scene_api.dart b/lib/services/api/scene_api.dart index b4397ac..b0e2511 100644 --- a/lib/services/api/scene_api.dart +++ b/lib/services/api/scene_api.dart @@ -202,12 +202,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), + .replaceAll('{automationId}', automationId) + .replaceAll('{projectId}', projectId), body: createAutomationModel .toJson(automationId.isNotEmpty == true ? automationId : null), expectedResponseModel: (json) { From a64a41548fcc9eeb8966cc83cdc6882e1b068724 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Fri, 14 Mar 2025 13:02:14 +0400 Subject: [PATCH 5/5] updated delete endpoint for automation --- .../scene/bloc/create_scene/create_scene_bloc.dart | 10 +++++++--- lib/features/scene/bloc/scene_bloc/scene_bloc.dart | 11 ++++++----- lib/services/api/api_links_endpoints.dart | 4 ++-- lib/services/api/scene_api.dart | 14 +++++++++----- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart index 2ded3e5..17a5b51 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart @@ -360,8 +360,8 @@ class CreateSceneBloc extends Bloc response = event.updateScene ? await SceneApi.updateAutomation(event.createAutomationModel!, event.sceneId, project?.uuid ?? '') - : await SceneApi.createAutomation(event.createAutomationModel!, - project?.uuid ?? ''); + : await SceneApi.createAutomation( + event.createAutomationModel!, project?.uuid ?? ''); } if (response['success'] == true) { @@ -613,10 +613,14 @@ class CreateSceneBloc extends Bloc emit(DeleteSceneLoading()); try { + Project? project = HomeCubit.getInstance().project; + final response = sceneType.name == CreateSceneEnum.deviceStatusChanges.name ? await SceneApi.deleteAutomation( - automationId: event.sceneId, unitUuid: event.unitUuid) + automationId: event.sceneId, + unitUuid: event.unitUuid, + projectId: project?.uuid ?? '') : await SceneApi.deleteScene( sceneId: event.sceneId, ); diff --git a/lib/features/scene/bloc/scene_bloc/scene_bloc.dart b/lib/features/scene/bloc/scene_bloc/scene_bloc.dart index 3c21d60..28c3ee1 100644 --- a/lib/features/scene/bloc/scene_bloc/scene_bloc.dart +++ b/lib/features/scene/bloc/scene_bloc/scene_bloc.dart @@ -102,13 +102,14 @@ class SceneBloc extends Bloc { Project? project = HomeCubit.getInstance().project; final success = await SceneApi.updateAutomationStatus( - event.automationId, event.automationStatusUpdate); + event.automationId, + event.automationStatusUpdate, + project?.uuid ?? ''); if (success) { automationList = await SceneApi.getAutomationByUnitId( - event.automationStatusUpdate.spaceUuid, - event.communityId, - project?.uuid ?? '' - ); + event.automationStatusUpdate.spaceUuid, + event.communityId, + project?.uuid ?? ''); newLoadingStates[event.automationId] = false; emit(SceneLoaded( currentState.scenes, diff --git a/lib/services/api/api_links_endpoints.dart b/lib/services/api/api_links_endpoints.dart index 78591f1..b66f061 100644 --- a/lib/services/api/api_links_endpoints.dart +++ b/lib/services/api/api_links_endpoints.dart @@ -164,12 +164,12 @@ abstract class ApiEndpoints { static const String updateAutomation = '/projects/{projectId}/automations/{automationId}'; static const String updateAutomationStatus = - '/automation/status/{automationId}'; + '/projects/{projectId}/automations/{automationId}'; /// DELETE static const String deleteScene = '/scene/tap-to-run/{sceneId}'; - static const String deleteAutomation = '/automation/{automationId}'; + static const String deleteAutomation = '/projects/{projectId}/automations/{automationId}'; //////////////////////Door Lock ////////////////////// //online diff --git a/lib/services/api/scene_api.dart b/lib/services/api/scene_api.dart index b0e2511..db47396 100644 --- a/lib/services/api/scene_api.dart +++ b/lib/services/api/scene_api.dart @@ -136,11 +136,12 @@ class SceneApi { //updateAutomationStatus static Future updateAutomationStatus(String automationId, - AutomationStatusUpdate createAutomationEnable) async { + AutomationStatusUpdate createAutomationEnable, String projectId) async { try { - final response = await _httpService.put( + final response = await _httpService.patch( path: ApiEndpoints.updateAutomationStatus - .replaceAll('{automationId}', automationId), + .replaceAll('{automationId}', automationId) + .replaceAll('{projectId}', projectId), body: createAutomationEnable.toMap(), expectedResponseModel: (json) => json['success'], ); @@ -238,11 +239,14 @@ class SceneApi { // delete automation static Future deleteAutomation( - {required String unitUuid, required String automationId}) async { + {required String unitUuid, + required String automationId, + required String projectId}) async { try { final response = await _httpService.delete( path: ApiEndpoints.deleteAutomation - .replaceAll('{automationId}', automationId), + .replaceAll('{automationId}', automationId) + .replaceAll('{projectId}', projectId), showServerMessage: false, expectedResponseModel: (json) => json['statusCode'] == 200, );