backend-demo-tn/src/main/java/com/cubetiqs/demo/rest/UserController.java

34 lines
902 B
Java
Raw Normal View History

2020-06-11 19:13:29 +07:00
package com.cubetiqs.demo.rest;
import com.cubetiqs.demo.domain.UserEntity;
import com.cubetiqs.demo.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(path = {"/users"})
public class UserController {
private final UserRepository userRepository;
@Autowired
public UserController(UserRepository userRepository) {
this.userRepository = userRepository;
}
@GetMapping
public Page<UserEntity> getAllUsers(Pageable pageable) {
return userRepository.findAll(pageable);
}
@PostMapping
public UserEntity createUser(
@RequestBody UserEntity user
) {
return userRepository.save(user);
}
}