added User controller, renamed DeviceController

This commit is contained in:
Tommaso Rodolfo Masera 2020-02-25 14:38:14 +01:00
parent 2681806091
commit e26f5976c6
2 changed files with 43 additions and 2 deletions

View file

@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@EnableAutoConfiguration @EnableAutoConfiguration
@RequestMapping("/dimmableLight") @RequestMapping("/dimmableLight")
public class DeviceController { public class DimmableLightController {
@Autowired private DimmableLightRepository dimmableLightService; @Autowired private DimmableLightRepository dimmableLightService;
@ -28,7 +28,7 @@ public class DeviceController {
@GetMapping("/{id}") @GetMapping("/{id}")
public DimmableLight getById(@PathVariable("id") long id) { public DimmableLight getById(@PathVariable("id") long id) {
return dimmableLightService.getList(); return dimmableLightService.getById();
} }
@PostMapping @PostMapping

View file

@ -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<User> 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);
}
}