fixed user controller

This commit is contained in:
Tommaso Rodolfo Masera 2020-02-25 15:44:10 +01:00
parent e26f5976c6
commit 03fed60a34
2 changed files with 12 additions and 12 deletions

View file

@ -4,38 +4,37 @@ 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
@RequestMapping("/user")
public class UserController {
@Autowired private UserRepository userRepository;
@GetMapping
public List<User> getAll() {
return userRepository.getList();
public Iterable<User> findAll() {
return userRepository.findAll();
}
@GetMapping("/{id}")
public User getById(@PathVariable("id") long id) {
return userRepository.getById();
public Optional<User> findById(@PathVariable("id") long id) {
return userRepository.findById(id);
}
@PostMapping
public User create(@RequestBody User u) {
return userRepository.create(u);
public User save(@RequestBody User u) {
return userRepository.save(u);
}
@PutMapping("/{id}")
public User update(@PathVariable("id") long id, @RequestBody User u) {
return userRepository.update(id, u);
public User update(@RequestBody User u) {
return userRepository.save(u);
}
@DeleteMapping("/{id}")
public void delete(@PathVariable("id") long id) {
userRepository.delete(id);
public void deleteById(@PathVariable("id") long id) {
userRepository.deleteById(id);
}
}

View file

@ -1,5 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import java.util.*;
import org.springframework.data.repository.CrudRepository;
public interface UserRepository extends CrudRepository<User, Long> {}