mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-26 11:24:54 +00:00
changed endpoint for create automation endpoint
This commit is contained in:
@ -1,6 +1,8 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/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_bloc.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_event.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/features/scene/model/scene_static_function.dart';
|
||||||
import 'package:syncrow_app/navigation/navigation_service.dart';
|
import 'package:syncrow_app/navigation/navigation_service.dart';
|
||||||
import 'package:syncrow_app/services/api/scene_api.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';
|
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||||
|
|
||||||
part 'create_scene_event.dart';
|
part 'create_scene_event.dart';
|
||||||
@ -348,6 +351,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
emit(CreateSceneLoading());
|
emit(CreateSceneLoading());
|
||||||
try {
|
try {
|
||||||
dynamic response;
|
dynamic response;
|
||||||
|
Project? project = HomeCubit.getInstance().project;
|
||||||
|
|
||||||
if (event.createSceneModel != null) {
|
if (event.createSceneModel != null) {
|
||||||
response = event.updateScene
|
response = event.updateScene
|
||||||
? await SceneApi.updateScene(event.createSceneModel!, event.sceneId)
|
? await SceneApi.updateScene(event.createSceneModel!, event.sceneId)
|
||||||
@ -356,7 +361,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
response = event.updateScene
|
response = event.updateScene
|
||||||
? await SceneApi.updateAutomation(
|
? await SceneApi.updateAutomation(
|
||||||
event.createAutomationModel!, event.sceneId)
|
event.createAutomationModel!, event.sceneId)
|
||||||
: await SceneApi.createAutomation(event.createAutomationModel!);
|
: await SceneApi.createAutomation(event.createAutomationModel!,
|
||||||
|
project?.uuid ?? TempConst.projectIdDev);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response['success'] == true) {
|
if (response['success'] == true) {
|
||||||
|
|||||||
@ -144,7 +144,7 @@ abstract class ApiEndpoints {
|
|||||||
/// POST
|
/// POST
|
||||||
static const String createScene = '/scene/tap-to-run';
|
static const String createScene = '/scene/tap-to-run';
|
||||||
static const String triggerScene = '/scene/tap-to-run/{sceneId}/trigger';
|
static const String triggerScene = '/scene/tap-to-run/{sceneId}/trigger';
|
||||||
static const String createAutomation = '/automation';
|
static const String createAutomation = '/projects/{projectId}/automations';
|
||||||
|
|
||||||
/// GET
|
/// GET
|
||||||
static const String getUnitScenes =
|
static const String getUnitScenes =
|
||||||
|
|||||||
@ -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/features/scene/model/update_automation.dart';
|
||||||
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
||||||
import 'package:syncrow_app/services/api/http_service.dart';
|
import 'package:syncrow_app/services/api/http_service.dart';
|
||||||
import 'package:syncrow_app/utils/constants/temp_const.dart';
|
|
||||||
|
|
||||||
class SceneApi {
|
class SceneApi {
|
||||||
static final HTTPService _httpService = HTTPService();
|
static final HTTPService _httpService = HTTPService();
|
||||||
@ -31,10 +30,11 @@ class SceneApi {
|
|||||||
|
|
||||||
// create automation
|
// create automation
|
||||||
static Future<Map<String, dynamic>> createAutomation(
|
static Future<Map<String, dynamic>> createAutomation(
|
||||||
CreateAutomationModel createAutomationModel) async {
|
CreateAutomationModel createAutomationModel, String projectId) async {
|
||||||
try {
|
try {
|
||||||
final response = await _httpService.post(
|
final response = await _httpService.post(
|
||||||
path: ApiEndpoints.createAutomation,
|
path:
|
||||||
|
ApiEndpoints.createAutomation.replaceAll('{projectId}', projectId),
|
||||||
body: createAutomationModel.toMap(),
|
body: createAutomationModel.toMap(),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
|
|||||||
Reference in New Issue
Block a user