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

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

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

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

View file

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

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

View file

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

View file

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

View file

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