From e26f5976c6e005b54ede734fef4f5db6b13a9de5 Mon Sep 17 00:00:00 2001 From: tommi27 Date: Tue, 25 Feb 2020 14:38:14 +0100 Subject: [PATCH] added User controller, renamed DeviceController --- ...ller.java => DimmableLightController.java} | 4 +- .../smarthut/controller/UserController.java | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) rename src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/{DeviceController.java => DimmableLightController.java} (95%) create mode 100644 src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserController.java diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DeviceController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java similarity index 95% rename from src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DeviceController.java rename to src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java index 60f5c5d..0cd1144 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DeviceController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java @@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController @EnableAutoConfiguration @RequestMapping("/dimmableLight") -public class DeviceController { +public class DimmableLightController { @Autowired private DimmableLightRepository dimmableLightService; @@ -28,7 +28,7 @@ public class DeviceController { @GetMapping("/{id}") public DimmableLight getById(@PathVariable("id") long id) { - return dimmableLightService.getList(); + return dimmableLightService.getById(); } @PostMapping diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserController.java new file mode 100644 index 0000000..5829446 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserController.java @@ -0,0 +1,41 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.controller; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; +import java.util.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.*; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +@RestController +@EnableAutoConfiguration +@Controller +public class UserController { + + @Autowired private UserRepository userRepository; + + @GetMapping + public List getAll() { + return userRepository.getList(); + } + + @GetMapping("/{id}") + public User getById(@PathVariable("id") long id) { + return userRepository.getById(); + } + + @PostMapping + public User create(@RequestBody User u) { + return userRepository.create(u); + } + + @PutMapping("/{id}") + public User update(@PathVariable("id") long id, @RequestBody User u) { + return userRepository.update(id, u); + } + + @DeleteMapping("/{id}") + public void delete(@PathVariable("id") long id) { + userRepository.delete(id); + } +}