Class UserController

java.lang.Object
dev.fernando.user_authentication_api.controller.UserController

@RestController @RequestMapping("/user") public class UserController extends Object
REST controller for managing users. Provides endpoints for creating, retrieving, updating, and deleting users. Uses HATEOAS for response enrichment.
Since:
1.0.0
Author:
Fernando Cruz Cavina
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a UserController with the given UserService.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<org.springframework.hateoas.EntityModel<ViewUserDto>>
    createUser(CreateUserDto createUserDto)
    This endpoint allows the creation of a user with a default role, typically used for client accounts.
    org.springframework.http.ResponseEntity<org.springframework.hateoas.EntityModel<ViewUserDto>>
    This endpoint deletes a user by email.
    org.springframework.http.ResponseEntity<org.springframework.hateoas.EntityModel<ViewUserDto>>
    This endpoint deletes a user by ID.
    org.springframework.http.ResponseEntity<org.springframework.hateoas.EntityModel<ViewUserDto>>
    This endpoint allows retrieval of user details using their email address.
    org.springframework.http.ResponseEntity<org.springframework.hateoas.EntityModel<ViewUserDto>>
    This endpoint allows retrieval of user details using their ID.
    org.springframework.http.ResponseEntity<org.springframework.hateoas.EntityModel<ViewUserDto>>
    updateUser(Long id, UpdateUserDto updateUserDto)
    This endpoint allows updating user details by ID.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • UserController

      public UserController(UserService userService)
      Constructs a UserController with the given UserService.
      Parameters:
      userService - the user service that provides user-related operations
  • Method Details

    • getUserById

      @GetMapping("/id/{id}") public org.springframework.http.ResponseEntity<org.springframework.hateoas.EntityModel<ViewUserDto>> getUserById(@PathVariable("id") Long id)
      This endpoint allows retrieval of user details using their ID.
      Parameters:
      id - the user ID
      Returns:
      the user details wrapped in an EntityModel
    • getUserByEmail

      @GetMapping("/email/{email}") public org.springframework.http.ResponseEntity<org.springframework.hateoas.EntityModel<ViewUserDto>> getUserByEmail(@PathVariable("email") String email)
      This endpoint allows retrieval of user details using their email address.
      Parameters:
      email - the user email
      Returns:
      the user details wrapped in an EntityModel
    • createUser

      @PostMapping public org.springframework.http.ResponseEntity<org.springframework.hateoas.EntityModel<ViewUserDto>> createUser(@RequestBody CreateUserDto createUserDto)
      This endpoint allows the creation of a user with a default role, typically used for client accounts.
      Parameters:
      createUserDto - the user data sent in the request body
      Returns:
      the created user details(ViewUserDto) wrapped in an EntityModel with HATEOAS links
    • updateUser

      @PutMapping("/id/{id}") public org.springframework.http.ResponseEntity<org.springframework.hateoas.EntityModel<ViewUserDto>> updateUser(@PathVariable Long id, @RequestBody UpdateUserDto updateUserDto)
      This endpoint allows updating user details by ID. The user must provide the current password to confirm the update.
      Parameters:
      id - the user ID wanting to be updated
      updateUserDto - the updated user data sent in the request body
      Returns:
      the updated user details(ViewUserDto) wrapped in an EntityModel with HATEOAS links
    • deleteUserById

      @DeleteMapping("/id/{id}") public org.springframework.http.ResponseEntity<org.springframework.hateoas.EntityModel<ViewUserDto>> deleteUserById(@PathVariable("id") Long id)
      This endpoint deletes a user by ID.
      Parameters:
      id - the user ID to be deleted
      Returns:
      the deleted user details wrapped in an EntityModel
    • deleteUserByEmail

      @DeleteMapping("/email/{email}") public org.springframework.http.ResponseEntity<org.springframework.hateoas.EntityModel<ViewUserDto>> deleteUserByEmail(@PathVariable String email)
      This endpoint deletes a user by email.
      Parameters:
      email - the user email to be deleted
      Returns:
      the deleted user details wrapped in an EntityModel