From 3cedaf5f50ac8224a87e52873dd8537692c5cfa4 Mon Sep 17 00:00:00 2001 From: omenem Date: Fri, 17 Apr 2020 18:28:42 +0200 Subject: [PATCH] Fix --- .../controller/ThermostatStateController.java | 67 +++++++++---------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatStateController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatStateController.java index cbc0a91..4f83c29 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatStateController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatStateController.java @@ -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 findAll() { + return toList(thermostatStateService.findAll()); + } - @GetMapping - public List 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); } }