Merge branch '47-fix-cascade-deletion-when-room-is-deleted' into 'dev'
Resolve "Fix cascade deletion when room is deleted" Closes #47 See merge request sa4-2020/the-sanmarinoes/backend!59
This commit is contained in:
commit
03bbf6b824
6 changed files with 32 additions and 5 deletions
|
@ -23,6 +23,12 @@ public class RoomController {
|
|||
|
||||
@Autowired private DeviceRepository<Device> deviceRepository;
|
||||
|
||||
@Autowired private SwitchRepository switchRepository;
|
||||
|
||||
@Autowired private ButtonDimmerRepository buttonDimmerRepository;
|
||||
|
||||
@Autowired private KnobDimmerRepository knobDimmerRepository;
|
||||
|
||||
@GetMapping
|
||||
public List<Room> findAll() {
|
||||
return toList(roomRepository.findAll());
|
||||
|
@ -81,6 +87,9 @@ public class RoomController {
|
|||
|
||||
@DeleteMapping("/{id}")
|
||||
public void deleteById(@PathVariable("id") long id) {
|
||||
switchRepository.deleteAllByRoomId(id);
|
||||
knobDimmerRepository.deleteAllByRoomId(id);
|
||||
buttonDimmerRepository.deleteAllByRoomId(id);
|
||||
roomRepository.deleteById(id);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ public class DimmableLightSaveRequest {
|
|||
|
||||
/** The light intensity value. Goes from 0 (off) to 100 (on) */
|
||||
@NotNull
|
||||
@Min(1)
|
||||
@Min(0)
|
||||
@Max(100)
|
||||
private Integer intensity = 0;
|
||||
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||
|
||||
public interface ButtonDimmerRepository extends DeviceRepository<ButtonDimmer> {}
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
public interface ButtonDimmerRepository extends DeviceRepository<ButtonDimmer> {
|
||||
|
||||
@Transactional
|
||||
void deleteAllByRoomId(long roomId);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||
|
||||
public interface KnobDimmerRepository extends DeviceRepository<KnobDimmer> {}
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
public interface KnobDimmerRepository extends DeviceRepository<KnobDimmer> {
|
||||
|
||||
@Transactional
|
||||
void deleteAllByRoomId(long roomId);
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class Switch extends InputDevice {
|
|||
}
|
||||
|
||||
@PreRemove
|
||||
private void removeSwitchable() {
|
||||
public void removeSwitchable() {
|
||||
for (Switchable s : getOutputs()) {
|
||||
s.setSwitchId(null);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||
|
||||
public interface SwitchRepository extends DeviceRepository<Switch> {}
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
public interface SwitchRepository extends DeviceRepository<Switch> {
|
||||
|
||||
@Transactional
|
||||
void deleteAllByRoomId(long roomId);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue