fix room deletion

This commit is contained in:
omenem 2020-03-25 14:14:12 +01:00
parent bcade19f52
commit 9fc0224b1d
5 changed files with 31 additions and 4 deletions

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -54,7 +54,7 @@ public class Switch extends InputDevice {
}
@PreRemove
private void removeSwitchable() {
public void removeSwitchable() {
for (Switchable s : getOutputs()) {
s.setSwitchId(null);
}

View file

@ -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);
}