This commit is contained in:
omenem 2020-04-27 11:54:31 +02:00
parent 15c6e99e4e
commit cc2a16f3e3
3 changed files with 18 additions and 1 deletions

View file

@ -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.error.NotFoundException;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ScenePriority; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ScenePriority;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ScenePriorityRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ScenePriorityRepository;
import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@ -28,6 +29,12 @@ public class ScenePriorityController {
return scenePriorityRepository.findById(id).orElseThrow(NotFoundException::new); return scenePriorityRepository.findById(id).orElseThrow(NotFoundException::new);
} }
@GetMapping("/{automationId}")
public List<ScenePriority> getByAutomationId(@PathVariable long automationId)
throws NotFoundException {
return scenePriorityRepository.findAllByAutomationId(automationId);
}
private ScenePriority save(ScenePriority newRL, ScenePrioritySaveRequest s) { private ScenePriority save(ScenePriority newRL, ScenePrioritySaveRequest s) {
newRL.setPriority(s.getPriority()); newRL.setPriority(s.getPriority());
newRL.setAutomationId(s.getAutomationId()); newRL.setAutomationId(s.getAutomationId());

View file

@ -1,8 +1,11 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models; package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude; import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude;
import io.swagger.annotations.ApiModelProperty;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
@ -13,6 +16,12 @@ import javax.validation.constraints.NotNull;
@Entity @Entity
public class ScenePriority { public class ScenePriority {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false, unique = true)
@ApiModelProperty(hidden = true)
private long id;
@ManyToOne @ManyToOne
@JoinColumn(name = "automation_id", updatable = false, insertable = false) @JoinColumn(name = "automation_id", updatable = false, insertable = false)
@GsonExclude @GsonExclude
@ -32,7 +41,6 @@ public class ScenePriority {
@GsonExclude @GsonExclude
private Scene scene; private Scene scene;
@Id
@Column(name = "scene_id", nullable = false, updatable = false, unique = true) @Column(name = "scene_id", nullable = false, updatable = false, unique = true)
@NotNull @NotNull
private Long sceneId; private Long sceneId;

View file

@ -9,4 +9,6 @@ public interface ScenePriorityRepository extends CrudRepository<ScenePriority, L
List<ScenePriority> findAllBySceneId(@Param("sceneId") long sceneId); List<ScenePriority> findAllBySceneId(@Param("sceneId") long sceneId);
void deleteBySceneId(@Param("sceneId") long sceneId); void deleteBySceneId(@Param("sceneId") long sceneId);
List<ScenePriority> findAllByAutomationId(@Param("automationId") long automationId);
} }