From cc2a16f3e308a13e8f43571635729fc69d4a1d47 Mon Sep 17 00:00:00 2001 From: omenem Date: Mon, 27 Apr 2020 11:54:31 +0200 Subject: [PATCH] fix --- .../smarthut/controller/ScenePriorityController.java | 7 +++++++ .../sa4/sanmarinoes/smarthut/models/ScenePriority.java | 10 +++++++++- .../smarthut/models/ScenePriorityRepository.java | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ScenePriorityController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ScenePriorityController.java index d0bbb5a..8711d57 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ScenePriorityController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ScenePriorityController.java @@ -4,6 +4,7 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.ScenePrioritySaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ScenePriority; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ScenePriorityRepository; +import java.util.List; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -28,6 +29,12 @@ public class ScenePriorityController { return scenePriorityRepository.findById(id).orElseThrow(NotFoundException::new); } + @GetMapping("/{automationId}") + public List getByAutomationId(@PathVariable long automationId) + throws NotFoundException { + return scenePriorityRepository.findAllByAutomationId(automationId); + } + private ScenePriority save(ScenePriority newRL, ScenePrioritySaveRequest s) { newRL.setPriority(s.getPriority()); newRL.setAutomationId(s.getAutomationId()); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ScenePriority.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ScenePriority.java index 0652e5e..d34714b 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ScenePriority.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ScenePriority.java @@ -1,8 +1,11 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude; +import io.swagger.annotations.ApiModelProperty; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; @@ -13,6 +16,12 @@ import javax.validation.constraints.NotNull; @Entity public class ScenePriority { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", updatable = false, nullable = false, unique = true) + @ApiModelProperty(hidden = true) + private long id; + @ManyToOne @JoinColumn(name = "automation_id", updatable = false, insertable = false) @GsonExclude @@ -32,7 +41,6 @@ public class ScenePriority { @GsonExclude private Scene scene; - @Id @Column(name = "scene_id", nullable = false, updatable = false, unique = true) @NotNull private Long sceneId; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ScenePriorityRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ScenePriorityRepository.java index 020a369..1d9b3c6 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ScenePriorityRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ScenePriorityRepository.java @@ -9,4 +9,6 @@ public interface ScenePriorityRepository extends CrudRepository findAllBySceneId(@Param("sceneId") long sceneId); void deleteBySceneId(@Param("sceneId") long sceneId); + + List findAllByAutomationId(@Param("automationId") long automationId); }