Class UserProfileController

java.lang.Object
api.mpba.rastvdmy.controller.UserProfileController

@RestController @RequestMapping(path="/api/v1/users") public class UserProfileController extends Object
The UserProfileController handles all operations related to user profiles in the application. It provides endpoints for user management, including creating, updating, retrieving, and deleting user profiles. Access to these endpoints is secured based on user roles.
  • Constructor Summary

    Constructors
    Constructor
    Description
    UserProfileController(UserProfileService userProfileService, UserProfileMapper userProfileMapper)
    Constructs a UserProfileController with the specified user profile service and user profile mapper.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<Void>
    deleteMyProfile(jakarta.servlet.http.HttpServletRequest request)
    Deletes the profile of the currently authenticated user.
    org.springframework.http.ResponseEntity<Void>
    deleteUserProfile(jakarta.servlet.http.HttpServletRequest request, UUID userId)
    Deletes a user profile by user ID.
    org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<UserProfileResponse>>
    filterAndSortUsers(jakarta.servlet.http.HttpServletRequest request, int page, int size, String sort)
    Filters and sorts user profiles.
    org.springframework.http.ResponseEntity<UserProfileResponse>
    getUser(jakarta.servlet.http.HttpServletRequest request)
    Retrieves the profile of the currently authenticated user.
    org.springframework.http.ResponseEntity<UserProfileResponse>
    getUserById(jakarta.servlet.http.HttpServletRequest request, UUID userId)
    Retrieves a user profile by user ID.
    org.springframework.http.ResponseEntity<List<UserProfileResponse>>
    getUsers(jakarta.servlet.http.HttpServletRequest request)
    Retrieves all user profiles.
    org.springframework.http.ResponseEntity<UserTokenResponse>
    manageUserAvatar(jakarta.servlet.http.HttpServletRequest request, String action, org.springframework.web.multipart.MultipartFile userAvatar)
    Manages the avatar of the currently authenticated user.
    org.springframework.http.ResponseEntity<UserTokenResponse>
    updateUser(jakarta.servlet.http.HttpServletRequest request, @Valid UserUpdateRequest updateRequest)
    Updates the profile of the currently authenticated user.
    org.springframework.http.ResponseEntity<Void>
    updateUserRole(jakarta.servlet.http.HttpServletRequest request, UUID userId)
    Updates the role of a user by user ID.
    org.springframework.http.ResponseEntity<UserTokenResponse>
    updateUserSpecificCredentials(jakarta.servlet.http.HttpServletRequest request, UUID userId, @Valid AdminUpdateUserRequest updateRequest)
    Updates specific credentials of a user by user ID.
    org.springframework.http.ResponseEntity<Void>
    updateUserStatus(jakarta.servlet.http.HttpServletRequest request, UUID userId)
    Updates the status of a user by user ID.

    Methods inherited from class java.lang.Object

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

    • UserProfileController

      public UserProfileController(UserProfileService userProfileService, UserProfileMapper userProfileMapper)
      Constructs a UserProfileController with the specified user profile service and user profile mapper.
      Parameters:
      userProfileService - the user profile service
      userProfileMapper - the user profile mapper
  • Method Details

    • getUsers

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @GetMapping(produces="application/json") public org.springframework.http.ResponseEntity<List<UserProfileResponse>> getUsers(jakarta.servlet.http.HttpServletRequest request)
      Retrieves all user profiles.
      Parameters:
      request - the HTTP request
      Returns:
      a list of user profile responses
    • getUser

      @PreAuthorize("hasAnyRole(\'ROLE_DEFAULT\', \'ROLE_ADMIN\')") @GetMapping(path="/me", produces="application/json") public org.springframework.http.ResponseEntity<UserProfileResponse> getUser(jakarta.servlet.http.HttpServletRequest request)
      Retrieves the profile of the currently authenticated user.
      Parameters:
      request - the HTTP request
      Returns:
      the user profile response
    • getUserById

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @GetMapping(path="/{id}", produces="application/json") public org.springframework.http.ResponseEntity<UserProfileResponse> getUserById(jakarta.servlet.http.HttpServletRequest request, @PathVariable("id") UUID userId)
      Retrieves a user profile by user ID.
      Parameters:
      request - the HTTP request
      userId - the ID of the user
      Returns:
      the user profile response
    • filterAndSortUsers

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @GetMapping(path="/filter", produces="application/json") public org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<UserProfileResponse>> filterAndSortUsers(jakarta.servlet.http.HttpServletRequest request, @RequestParam(value="page",defaultValue="0") int page, @RequestParam(value="size",defaultValue="10") int size, @RequestParam(value="sort",defaultValue="asc") String sort)
      Filters and sorts user profiles.
      Parameters:
      request - the HTTP request
      page - the page number
      size - the page size
      sort - the sort order
      Returns:
      a page of user profile responses
    • updateUser

      @PreAuthorize("hasRole(\'ROLE_DEFAULT\')") @PatchMapping(path="/me", consumes="application/json", produces="application/json") public org.springframework.http.ResponseEntity<UserTokenResponse> updateUser(jakarta.servlet.http.HttpServletRequest request, @Valid @RequestBody @Valid UserUpdateRequest updateRequest) throws Exception
      Updates the profile of the currently authenticated user.
      Parameters:
      request - the HTTP request
      updateRequest - the user update request
      Returns:
      the user token response
      Throws:
      Exception - if an error occurs during the update
    • updateUserSpecificCredentials

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PatchMapping(path="/{id}", consumes="application/json", produces="application/json") public org.springframework.http.ResponseEntity<UserTokenResponse> updateUserSpecificCredentials(jakarta.servlet.http.HttpServletRequest request, @PathVariable("id") UUID userId, @Valid @RequestBody @Valid AdminUpdateUserRequest updateRequest)
      Updates specific credentials of a user by user ID.
      Parameters:
      request - the HTTP request
      userId - the ID of the user
      updateRequest - the admin update user request
      Returns:
      the user token response
    • manageUserAvatar

      @PreAuthorize("hasRole(\'ROLE_DEFAULT\')") @PatchMapping(path="/me/avatar", consumes="multipart/form-data", produces="application/json") public org.springframework.http.ResponseEntity<UserTokenResponse> manageUserAvatar(jakarta.servlet.http.HttpServletRequest request, @RequestParam("action") String action, @RequestParam(value="user_avatar",required=false) org.springframework.web.multipart.MultipartFile userAvatar)
      Manages the avatar of the currently authenticated user.
      Parameters:
      request - the HTTP request
      action - the action to perform (upload or remove)
      userAvatar - the user avatar file
      Returns:
      the user token response
    • updateUserRole

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PatchMapping(path="/role/{id}", produces="application/json") public org.springframework.http.ResponseEntity<Void> updateUserRole(jakarta.servlet.http.HttpServletRequest request, @PathVariable("id") UUID userId)
      Updates the role of a user by user ID.
      Parameters:
      request - the HTTP request
      userId - the ID of the user
      Returns:
      a response entity with no content
    • updateUserStatus

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PatchMapping(path="/status/{id}", produces="application/json") public org.springframework.http.ResponseEntity<Void> updateUserStatus(jakarta.servlet.http.HttpServletRequest request, @PathVariable("id") UUID userId)
      Updates the status of a user by user ID.
      Parameters:
      request - the HTTP request
      userId - the ID of the user
      Returns:
      a response entity with no content
    • deleteMyProfile

      @PreAuthorize("hasRole(\'ROLE_DEFAULT\')") @DeleteMapping(path="/me") public org.springframework.http.ResponseEntity<Void> deleteMyProfile(jakarta.servlet.http.HttpServletRequest request)
      Deletes the profile of the currently authenticated user.
      Parameters:
      request - the HTTP request
      Returns:
      a response entity with no content
    • deleteUserProfile

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @DeleteMapping(path="/{id}") public org.springframework.http.ResponseEntity<Void> deleteUserProfile(jakarta.servlet.http.HttpServletRequest request, @PathVariable("id") UUID userId)
      Deletes a user profile by user ID.
      Parameters:
      request - the HTTP request
      userId - the ID of the user
      Returns:
      a response entity with no content