This commit is contained in:
omenem 2020-04-17 18:28:42 +02:00
parent 80088c0dc3
commit 3cedaf5f50

View File

@ -19,49 +19,46 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@EnableAutoConfiguration
@RequestMapping("/thermostatState")
public class ThermostatStateController {
@RestController
@EnableAutoConfiguration
@RequestMapping("/thermostatState")
public class SwitchableStateController {
@Autowired private ThermostatStateRepository thermostatStateService;
@Autowired private ThermostatStateRepository thermostatStateService;
@GetMapping
public List<ThermostatState> findAll() {
return toList(thermostatStateService.findAll());
}
@GetMapping
public List<ThermostatState> findAll() {
return toList(thermostatStateService.findAll());
}
@GetMapping("/{id}")
public ThermostatState findById(@PathVariable("id") long id) throws NotFoundException {
return thermostatStateService.findById(id).orElseThrow(NotFoundException::new);
}
@GetMapping("/{id}")
public ThermostatState findById(@PathVariable("id") long id) throws NotFoundException {
return thermostatStateService.findById(id).orElseThrow(NotFoundException::new);
}
private ThermostatState save(ThermostatState initial, ThermostatStateSaveRequest ts) {
initial.setDeviceId(ts.getDeviceId());
initial.setSceneId(ts.getSceneId());
initial.setMode(ts.getMode());
private ThermostatState save(ThermostatState initial, ThermostatStateSaveRequest ts) {
initial.setDeviceId(ts.getDeviceId());
initial.setSceneId(ts.getSceneId());
initial.setMode(ts.getMode());
return thermostatStateService.save(initial);
}
return thermostatStateService.save(initial);
}
@PostMapping
public ThermostatState create(@Valid @RequestBody ThermostatStateSaveRequest dl) {
return save(new ThermostatState(), dl);
}
@PostMapping
public ThermostatState create(@Valid @RequestBody ThermostatStateSaveRequest dl) {
return save(new ThermostatState(), dl);
}
@PutMapping
public ThermostatState update(@Valid @RequestBody ThermostatStateSaveRequest ts)
throws NotFoundException {
return save(
thermostatStateService.findById(ts.getId()).orElseThrow(NotFoundException::new),
ts);
}
@PutMapping
public ThermostatState update(@Valid @RequestBody ThermostatStateSaveRequest ts)
throws NotFoundException {
return save(
thermostatStateService.findById(ts.getId()).orElseThrow(NotFoundException::new),
ts);
}
@DeleteMapping("/{id}")
public void delete(@PathVariable("id") long id) {
thermostatStateService.deleteById(id);
}
@DeleteMapping("/{id}")
public void delete(@PathVariable("id") long id) {
thermostatStateService.deleteById(id);
}
}