fixed request annotations

This commit is contained in:
Tommaso Rodolfo Masera 2020-03-02 16:15:52 +01:00
parent eb6e935892
commit 572134bba2
9 changed files with 33 additions and 47 deletions

View file

@ -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.ButtonDimmer;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ButtonDimmerRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ButtonDimmerRepository;
import java.util.Optional; import java.util.Optional;
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;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.*;
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;
@RestController @RestController
@EnableAutoConfiguration @EnableAutoConfiguration
@ -31,7 +26,7 @@ public class ButtonDimmerController {
} }
@PostMapping @PostMapping
public ButtonDimmer create(final ButtonDimmerSaveRequest bd) { public ButtonDimmer create(@Valid @RequestBody final ButtonDimmerSaveRequest bd) {
ButtonDimmer newBD = new ButtonDimmer(); ButtonDimmer newBD = new ButtonDimmer();
newBD.setLights(bd.getLights()); newBD.setLights(bd.getLights());
newBD.setId(bd.getId()); newBD.setId(bd.getId());
@ -43,7 +38,7 @@ public class ButtonDimmerController {
} }
@PutMapping @PutMapping
public ButtonDimmer update(ButtonDimmerSaveRequest bd) { public ButtonDimmer update(@Valid @RequestBody ButtonDimmerSaveRequest bd) {
return this.create(bd); return this.create(bd);
} }

View file

@ -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.DimmableLight;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLightRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLightRepository;
import java.util.Optional; import java.util.Optional;
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;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.*;
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;
@RestController @RestController
@EnableAutoConfiguration @EnableAutoConfiguration
@ -32,7 +27,7 @@ public class DimmableLightController {
} }
@PostMapping @PostMapping
public DimmableLight create(DimmableLightSaveRequest dl) { public DimmableLight create(@Valid @RequestBody DimmableLightSaveRequest dl) {
DimmableLight newDL = new DimmableLight(); DimmableLight newDL = new DimmableLight();
newDL.setIntensity(dl.getIntensity()); newDL.setIntensity(dl.getIntensity());
newDL.setId(dl.getId()); newDL.setId(dl.getId());
@ -44,7 +39,7 @@ public class DimmableLightController {
} }
@PutMapping @PutMapping
public DimmableLight update(DimmableLightSaveRequest dl) { public DimmableLight update(@Valid @RequestBody DimmableLightSaveRequest dl) {
return this.create(dl); return this.create(dl);
} }

View file

@ -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.KnobDimmer;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmerRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmerRepository;
import java.util.Optional; import java.util.Optional;
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;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.*;
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;
@RestController @RestController
@EnableAutoConfiguration @EnableAutoConfiguration
@ -32,7 +27,7 @@ public class KnobDimmerController {
} }
@PostMapping @PostMapping
public KnobDimmer create(KnobDimmerSaveRequest kd) { public KnobDimmer create(@Valid @RequestBody KnobDimmerSaveRequest kd) {
KnobDimmer newKD = new KnobDimmer(); KnobDimmer newKD = new KnobDimmer();
newKD.setLights(kd.getLights()); newKD.setLights(kd.getLights());
newKD.setId(kd.getId()); newKD.setId(kd.getId());
@ -44,7 +39,7 @@ public class KnobDimmerController {
} }
@PutMapping @PutMapping
public KnobDimmer update(KnobDimmerSaveRequest kd) { public KnobDimmer update(@Valid @RequestBody KnobDimmerSaveRequest kd) {
return this.create(kd); return this.create(kd);
} }

View file

@ -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.MotionSensor;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.MotionSensorRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.MotionSensorRepository;
import java.util.Optional; import java.util.Optional;
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;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.*;
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;
@RestController @RestController
@EnableAutoConfiguration @EnableAutoConfiguration
@ -32,7 +27,7 @@ public class MotionSensorController {
} }
@PostMapping @PostMapping
public MotionSensor create(MotionSensorSaveRequest ms) { public MotionSensor create(@Valid @RequestBody MotionSensorSaveRequest ms) {
MotionSensor newMS = new MotionSensor(); MotionSensor newMS = new MotionSensor();
newMS.setDetected(ms.isDetected()); newMS.setDetected(ms.isDetected());
newMS.setId(ms.getId()); newMS.setId(ms.getId());
@ -44,7 +39,7 @@ public class MotionSensorController {
} }
@PutMapping @PutMapping
public MotionSensor update(MotionSensorSaveRequest ms) { public MotionSensor update(@Valid @RequestBody MotionSensorSaveRequest ms) {
return this.create(ms); return this.create(ms);
} }

View file

@ -34,7 +34,7 @@ public class RegularLightController {
} }
@PostMapping @PostMapping
public RegularLight save(RegularLightSaveRequest rl) { public RegularLight create(@Valid @RequestBody RegularLightSaveRequest rl) {
RegularLight newRL = new RegularLight(); RegularLight newRL = new RegularLight();
newRL.setId(rl.getId()); newRL.setId(rl.getId());
newRL.setName(rl.getName()); newRL.setName(rl.getName());
@ -46,8 +46,8 @@ public class RegularLightController {
} }
@PutMapping @PutMapping
public RegularLight update(@Valid @RequestBody RegularLight rl) { public RegularLight update(@Valid @RequestBody RegularLightSaveRequest rl) {
return regularLightService.save(rl); return this.create(rl);
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")

View file

@ -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.dto.SensorSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
import java.util.*; import java.util.*;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.*; import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -25,7 +26,7 @@ public class SensorController {
} }
@PostMapping @PostMapping
public Sensor create(SensorSaveRequest s) { public Sensor create(@Valid @RequestBody SensorSaveRequest s) {
Sensor newSensor = new Sensor(); Sensor newSensor = new Sensor();
newSensor.setSensor(s.getSensor()); newSensor.setSensor(s.getSensor());
newSensor.setValue(s.getValue()); newSensor.setValue(s.getValue());
@ -38,7 +39,7 @@ public class SensorController {
} }
@PutMapping @PutMapping
public Sensor update(SensorSaveRequest s) { public Sensor update(@Valid @RequestBody SensorSaveRequest s) {
return this.create(s); return this.create(s);
} }

View file

@ -26,7 +26,7 @@ public class SmartPlugController {
} }
@PostMapping @PostMapping
public SmartPlug create(SmartPlugSaveRequest sp) { public SmartPlug create(@Valid @RequestBody SmartPlugSaveRequest sp) {
SmartPlug newSP = new SmartPlug(); SmartPlug newSP = new SmartPlug();
newSP.setOn(sp.isOn()); newSP.setOn(sp.isOn());
newSP.setId(sp.getId()); newSP.setId(sp.getId());
@ -38,8 +38,8 @@ public class SmartPlugController {
} }
@PutMapping @PutMapping
public SmartPlug update(@Valid @RequestBody SmartPlug sp) { public SmartPlug update(@Valid @RequestBody SmartPlugSaveRequest sp) {
return smartPlugRepository.save(sp); return this.create(sp);
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")

View file

@ -26,7 +26,7 @@ public class SwitchController {
} }
@PostMapping @PostMapping
public Switch save(SwitchSaveRequest s) { public Switch create(@Valid @RequestBody SwitchSaveRequest s) {
Switch newSwitch = new Switch(); Switch newSwitch = new Switch();
newSwitch.setId(s.getId()); newSwitch.setId(s.getId());
newSwitch.setName(s.getName()); newSwitch.setName(s.getName());
@ -38,8 +38,8 @@ public class SwitchController {
} }
@PutMapping @PutMapping
public Switch update(@Valid @RequestBody Switch s) { public Switch update(@Valid @RequestBody SwitchSaveRequest s) {
return switchRepository.save(s); return this.create(s);
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")

View file

@ -55,6 +55,11 @@ public class ButtonDimmer extends Dimmer {
lights.clear(); lights.clear();
} }
/**
* Get the lights
*
* @return duh
*/
public Set<DimmableLight> getLights() { public Set<DimmableLight> getLights() {
return this.lights; return this.lights;
} }