diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RoomController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RoomController.java index 9ff6e2e..b73c55a 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RoomController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RoomController.java @@ -18,6 +18,8 @@ public class RoomController { @Autowired private UserRepository userRepository; + @Autowired private DeviceRepository deviceRepository; + @GetMapping public Iterable findAll() { return roomRepository.findAll(); @@ -55,4 +57,14 @@ public class RoomController { public void deleteById(@PathVariable("id") long id) { roomRepository.deleteById(id); } + + /** + * Returns a List of all Devices that are present in a given room (identified by its + * id). + */ + @GetMapping(path = "/room/{roomid}/devices") + @ResponseBody + public List getDevices(@PathVariable("roomid") long roomid) { + return deviceRepository.findByRoomId(roomid); + } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmerRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmerRepository.java index a74e68f..484977a 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmerRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmerRepository.java @@ -1,5 +1,3 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -import org.springframework.data.repository.CrudRepository; - -public interface ButtonDimmerRepository extends CrudRepository {} +public interface ButtonDimmerRepository extends DeviceRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLightRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLightRepository.java index fd3fe43..484084b 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLightRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/DimmableLightRepository.java @@ -1,5 +1,3 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -import org.springframework.data.repository.CrudRepository; - -public interface DimmableLightRepository extends CrudRepository {} +public interface DimmableLightRepository extends DeviceRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmerRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmerRepository.java index 803ed90..7d7fc16 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmerRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmerRepository.java @@ -1,5 +1,3 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -import org.springframework.data.repository.CrudRepository; - -public interface KnobDimmerRepository extends CrudRepository {} +public interface KnobDimmerRepository extends DeviceRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensorRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensorRepository.java index e354262..aea240d 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensorRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/MotionSensorRepository.java @@ -1,5 +1,3 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -import org.springframework.data.repository.CrudRepository; - -public interface MotionSensorRepository extends CrudRepository {} +public interface MotionSensorRepository extends DeviceRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLightRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLightRepository.java index 7f3f4a6..43c4e17 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLightRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RegularLightRepository.java @@ -1,5 +1,3 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -import org.springframework.data.repository.CrudRepository; - -public interface RegularLightRepository extends CrudRepository {} +public interface RegularLightRepository extends DeviceRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SensorRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SensorRepository.java index cc4eefa..b796277 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SensorRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SensorRepository.java @@ -1,5 +1,3 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -import org.springframework.data.repository.CrudRepository; - -public interface SensorRepository extends CrudRepository {} +public interface SensorRepository extends DeviceRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlugRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlugRepository.java index 24897a0..0b2fd344 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlugRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SmartPlugRepository.java @@ -1,5 +1,3 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -import org.springframework.data.repository.CrudRepository; - -public interface SmartPlugRepository extends CrudRepository {} +public interface SmartPlugRepository extends DeviceRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRepository.java index c2e0be9..f06f465 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchRepository.java @@ -1,5 +1,3 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; -import org.springframework.data.repository.CrudRepository; - -public interface SwitchRepository extends CrudRepository {} +public interface SwitchRepository extends DeviceRepository {} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java index e4ce24e..7909fe8 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java @@ -2,11 +2,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; import java.util.Set; import javax.persistence.*; -import javax.validation.constraints.Email; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; +import javax.validation.constraints.*; /** A user of the Smarthut application */ @Entity(name = "smarthutuser") @@ -33,7 +29,11 @@ public class User { @NotNull @Column(nullable = false) @NotEmpty(message = "Please provide a password") - @Min(value = 6, message = "Your password should be at least 6 characters long") + @Size( + min = 6, + max = 255, + message = + "Your password should be at least 6 characters long and at most 255 chars long") private String password; /**