From 572134bba230c853845b093120fac16db5dedc42 Mon Sep 17 00:00:00 2001 From: tommi27 Date: Mon, 2 Mar 2020 16:15:52 +0100 Subject: [PATCH] fixed request annotations --- .../smarthut/controller/ButtonDimmerController.java | 13 ++++--------- .../controller/DimmableLightController.java | 13 ++++--------- .../smarthut/controller/KnobDimmerController.java | 13 ++++--------- .../smarthut/controller/MotionSensorController.java | 13 ++++--------- .../smarthut/controller/RegularLightController.java | 6 +++--- .../smarthut/controller/SensorController.java | 5 +++-- .../smarthut/controller/SmartPlugController.java | 6 +++--- .../smarthut/controller/SwitchController.java | 6 +++--- .../sanmarinoes/smarthut/models/ButtonDimmer.java | 5 +++++ 9 files changed, 33 insertions(+), 47 deletions(-) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ButtonDimmerController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ButtonDimmerController.java index 404d5ac..6ea2556 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ButtonDimmerController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ButtonDimmerController.java @@ -4,15 +4,10 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.ButtonDimmerSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ButtonDimmer; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ButtonDimmerRepository; import java.util.Optional; +import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration @@ -31,7 +26,7 @@ public class ButtonDimmerController { } @PostMapping - public ButtonDimmer create(final ButtonDimmerSaveRequest bd) { + public ButtonDimmer create(@Valid @RequestBody final ButtonDimmerSaveRequest bd) { ButtonDimmer newBD = new ButtonDimmer(); newBD.setLights(bd.getLights()); newBD.setId(bd.getId()); @@ -43,7 +38,7 @@ public class ButtonDimmerController { } @PutMapping - public ButtonDimmer update(ButtonDimmerSaveRequest bd) { + public ButtonDimmer update(@Valid @RequestBody ButtonDimmerSaveRequest bd) { return this.create(bd); } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java index a7f6d1a..f7e02d2 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java @@ -4,15 +4,10 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.DimmableLightSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLight; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLightRepository; import java.util.Optional; +import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration @@ -32,7 +27,7 @@ public class DimmableLightController { } @PostMapping - public DimmableLight create(DimmableLightSaveRequest dl) { + public DimmableLight create(@Valid @RequestBody DimmableLightSaveRequest dl) { DimmableLight newDL = new DimmableLight(); newDL.setIntensity(dl.getIntensity()); newDL.setId(dl.getId()); @@ -44,7 +39,7 @@ public class DimmableLightController { } @PutMapping - public DimmableLight update(DimmableLightSaveRequest dl) { + public DimmableLight update(@Valid @RequestBody DimmableLightSaveRequest dl) { return this.create(dl); } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/KnobDimmerController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/KnobDimmerController.java index a317826..6c93178 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/KnobDimmerController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/KnobDimmerController.java @@ -4,15 +4,10 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.KnobDimmerSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmer; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmerRepository; import java.util.Optional; +import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration @@ -32,7 +27,7 @@ public class KnobDimmerController { } @PostMapping - public KnobDimmer create(KnobDimmerSaveRequest kd) { + public KnobDimmer create(@Valid @RequestBody KnobDimmerSaveRequest kd) { KnobDimmer newKD = new KnobDimmer(); newKD.setLights(kd.getLights()); newKD.setId(kd.getId()); @@ -44,7 +39,7 @@ public class KnobDimmerController { } @PutMapping - public KnobDimmer update(KnobDimmerSaveRequest kd) { + public KnobDimmer update(@Valid @RequestBody KnobDimmerSaveRequest kd) { return this.create(kd); } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/MotionSensorController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/MotionSensorController.java index 2aa37de..8decc61 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/MotionSensorController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/MotionSensorController.java @@ -4,15 +4,10 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.MotionSensorSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.MotionSensor; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.MotionSensorRepository; import java.util.Optional; +import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration @@ -32,7 +27,7 @@ public class MotionSensorController { } @PostMapping - public MotionSensor create(MotionSensorSaveRequest ms) { + public MotionSensor create(@Valid @RequestBody MotionSensorSaveRequest ms) { MotionSensor newMS = new MotionSensor(); newMS.setDetected(ms.isDetected()); newMS.setId(ms.getId()); @@ -44,7 +39,7 @@ public class MotionSensorController { } @PutMapping - public MotionSensor update(MotionSensorSaveRequest ms) { + public MotionSensor update(@Valid @RequestBody MotionSensorSaveRequest ms) { return this.create(ms); } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RegularLightController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RegularLightController.java index e2a2f49..dd53ceb 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RegularLightController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RegularLightController.java @@ -34,7 +34,7 @@ public class RegularLightController { } @PostMapping - public RegularLight save(RegularLightSaveRequest rl) { + public RegularLight create(@Valid @RequestBody RegularLightSaveRequest rl) { RegularLight newRL = new RegularLight(); newRL.setId(rl.getId()); newRL.setName(rl.getName()); @@ -46,8 +46,8 @@ public class RegularLightController { } @PutMapping - public RegularLight update(@Valid @RequestBody RegularLight rl) { - return regularLightService.save(rl); + public RegularLight update(@Valid @RequestBody RegularLightSaveRequest rl) { + return this.create(rl); } @DeleteMapping("/{id}") diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java index fab5d85..788f32f 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java @@ -3,6 +3,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SensorSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; import java.util.*; +import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.*; import org.springframework.web.bind.annotation.*; @@ -25,7 +26,7 @@ public class SensorController { } @PostMapping - public Sensor create(SensorSaveRequest s) { + public Sensor create(@Valid @RequestBody SensorSaveRequest s) { Sensor newSensor = new Sensor(); newSensor.setSensor(s.getSensor()); newSensor.setValue(s.getValue()); @@ -38,7 +39,7 @@ public class SensorController { } @PutMapping - public Sensor update(SensorSaveRequest s) { + public Sensor update(@Valid @RequestBody SensorSaveRequest s) { return this.create(s); } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SmartPlugController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SmartPlugController.java index 0761532..3cf2cc0 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SmartPlugController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SmartPlugController.java @@ -26,7 +26,7 @@ public class SmartPlugController { } @PostMapping - public SmartPlug create(SmartPlugSaveRequest sp) { + public SmartPlug create(@Valid @RequestBody SmartPlugSaveRequest sp) { SmartPlug newSP = new SmartPlug(); newSP.setOn(sp.isOn()); newSP.setId(sp.getId()); @@ -38,8 +38,8 @@ public class SmartPlugController { } @PutMapping - public SmartPlug update(@Valid @RequestBody SmartPlug sp) { - return smartPlugRepository.save(sp); + public SmartPlug update(@Valid @RequestBody SmartPlugSaveRequest sp) { + return this.create(sp); } @DeleteMapping("/{id}") diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchController.java index 50c2b50..51f0858 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchController.java @@ -26,7 +26,7 @@ public class SwitchController { } @PostMapping - public Switch save(SwitchSaveRequest s) { + public Switch create(@Valid @RequestBody SwitchSaveRequest s) { Switch newSwitch = new Switch(); newSwitch.setId(s.getId()); newSwitch.setName(s.getName()); @@ -38,8 +38,8 @@ public class SwitchController { } @PutMapping - public Switch update(@Valid @RequestBody Switch s) { - return switchRepository.save(s); + public Switch update(@Valid @RequestBody SwitchSaveRequest s) { + return this.create(s); } @DeleteMapping("/{id}") diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java index 6f6def8..b2c907f 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ButtonDimmer.java @@ -55,6 +55,11 @@ public class ButtonDimmer extends Dimmer { lights.clear(); } + /** + * Get the lights + * + * @return duh + */ public Set getLights() { return this.lights; }