Package com.myfood.controllers
Class UserController
java.lang.Object
com.myfood.controllers.UserController
Controller class for handling user-related operations.
This controller provides endpoints for basic CRUD operations on users.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<?>
deleteUser
(Long id) Delete a user.org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<com.myfood.dto.UserDTO>>
getAllUser
(org.springframework.data.domain.Pageable pageable) Retrieve all users with simplified DTO representation.org.springframework.http.ResponseEntity<com.myfood.dto.UserDTO>
getOneUser
(Long id) Retrieve a specific user by its ID with simplified DTO representation.org.springframework.http.ResponseEntity<?>
saveUser
(com.myfood.dto.User entity) Create a new user.org.springframework.http.ResponseEntity<?>
updateUser
(Long id, com.myfood.dto.User entity) Update an existing user.
-
Constructor Details
-
UserController
public UserController()
-
-
Method Details
-
getAllUser
@PreAuthorize("hasRole(\'ADMIN\')") @GetMapping("/users") public org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<com.myfood.dto.UserDTO>> getAllUser(@PageableDefault(size=20,page=0,sort="id") org.springframework.data.domain.Pageable pageable) Retrieve all users with simplified DTO representation.- Returns:
- ResponseEntity containing a list of UserDTO representing all users.
-
getOneUser
@PreAuthorize("hasRole(\'ADMIN\')") @GetMapping("/user/{id}") public org.springframework.http.ResponseEntity<com.myfood.dto.UserDTO> getOneUser(@PathVariable(name="id") Long id) Retrieve a specific user by its ID with simplified DTO representation.- Parameters:
id
- The ID of the user to retrieve.- Returns:
- ResponseEntity containing the requested UserDTO or a 404 response if not found.
-
saveUser
@PreAuthorize("hasRole(\'ADMIN\')") @PostMapping("/user") public org.springframework.http.ResponseEntity<?> saveUser(@RequestBody com.myfood.dto.User entity) Create a new user. Assign the default role 'USER' if available.- Parameters:
entity
- The user to be created.- Returns:
- ResponseEntity indicating success or an error response.
-
updateUser
@PreAuthorize("hasRole(\'ADMIN\')") @PutMapping("/user/{id}") public org.springframework.http.ResponseEntity<?> updateUser(@PathVariable(name="id") Long id, @RequestBody com.myfood.dto.User entity) Update an existing user.- Parameters:
id
- The ID of the user to update.entity
- The updated user.- Returns:
- ResponseEntity indicating success or a 404 response if not found.
-
deleteUser
@PreAuthorize("hasRole(\'ADMIN\')") @DeleteMapping("/user/{id}") public org.springframework.http.ResponseEntity<?> deleteUser(@PathVariable(name="id") Long id) Delete a user.- Parameters:
id
- The ID of the user to delete.- Returns:
- ResponseEntity indicating success or a 404 response if the user is not found.
-