Class UserController
java.lang.Object
com.needleandstitch.pavuk.controller.UserController
REST controller for managing User objects.
This class provides endpoints for handling user-related operations such as retrieving users, signing up new users, handling authentication, logging out users, updating existing users, and deleting users.
Endpoints:
- GET /users Retrieve all roles
- GET /users/{id} Retrieve a role by its ID
- GET /users/current Retrive currently authenticated user
- POST /users/sign-up Register a new user
- POST /users/sign-in Sign in a user
- POST /users/sign-out Log out current user
- PUT /users/{id} Update an existing role
- DELETE /users/{id} Delete a role
- Since:
- 15.12.2024
- Version:
- 1.0.0
- Author:
- Needle & Stitch
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity
<Void> createUser
(User user, jakarta.servlet.http.HttpServletResponse response) Endpoint to register a new user.org.springframework.http.ResponseEntity
<Void> deleteUser
(Long id) Endpoint to delete a user by its ID.Endpoint to retrieve all users.org.springframework.http.ResponseEntity
<User> getCurrentUser
(jakarta.servlet.http.HttpServletRequest request) Endpoint to retrieve the currently authenticated user based on the JWT token from cookies.org.springframework.http.ResponseEntity
<User> getUserById
(Long id) Endpoint to retrieve a clothing item by its ID.org.springframework.http.ResponseEntity
<User> Endpoint to authenticate a user and return their information.org.springframework.http.ResponseEntity
<Void> signOut
(jakarta.servlet.http.HttpServletResponse response) Endpoint to log the user out by removing the JWT cookie.org.springframework.http.ResponseEntity
<Void> updateUser
(Long id, User userDetails) Endpoint to update an existing user by its ID.
-
Constructor Details
-
UserController
public UserController()
-
-
Method Details
-
getAllUsers
-
getUserById
@GetMapping("/{id}") public org.springframework.http.ResponseEntity<User> getUserById(@PathVariable Long id) Endpoint to retrieve a clothing item by its ID.- Parameters:
id
- The ID of the user.- Returns:
- A ResponseEntity containing the User object if found or a 404 Not Found status if the object does not exist.
-
getCurrentUser
@GetMapping("/current") public org.springframework.http.ResponseEntity<User> getCurrentUser(jakarta.servlet.http.HttpServletRequest request) Endpoint to retrieve the currently authenticated user based on the JWT token from cookies.- Parameters:
request
- The HTTP request containing the cookies- Returns:
- A ResponseEntity containing the current user and a status of OK (200) if authenticated, or UNAUTHORIZED (401) if not
-
createUser
@PostMapping("/sign-up") public org.springframework.http.ResponseEntity<Void> createUser(@RequestBody User user, jakarta.servlet.http.HttpServletResponse response) Endpoint to register a new user.- Parameters:
user
- The user information to be used for the registrationresponse
- The HTTP response for setting the JWT cookie- Returns:
- A ResponseEntity with a CREATED (201) status
-
signIn
@PostMapping("/sign-in") public org.springframework.http.ResponseEntity<User> signIn(@RequestBody User user, jakarta.servlet.http.HttpServletResponse response) Endpoint to authenticate a user and return their information.- Parameters:
user
- The user credentials (email and password)response
- The HTTP response for setting the JWT cookie- Returns:
- A ResponseEntity containing the authenticated user and a status of OK (200) if successful, or UNAUTHORIZED (401) if authentication fails.
-
signOut
@PostMapping("/sign-out") public org.springframework.http.ResponseEntity<Void> signOut(jakarta.servlet.http.HttpServletResponse response) Endpoint to log the user out by removing the JWT cookie.- Parameters:
response
- The HTTP response for removing the JWT cookie- Returns:
- A ResponseEntity with a status of OK (200).
-
updateUser
@PutMapping("/{id}") public org.springframework.http.ResponseEntity<Void> updateUser(@PathVariable Long id, @RequestBody User userDetails) Endpoint to update an existing user by its ID.- Parameters:
id
- The ID of the user to update.userDetails
- The updated User object.- Returns:
- A ResponseEntity with a 200 OK status if successful, or a 404 Not Found status if the object does not exist.
-
deleteUser
-