Class UserController

java.lang.Object
com.jangular.backend.controller.UserController

@RestController @RequestMapping("/api/users") public class UserController extends Object
  • Constructor Details

    • UserController

      public UserController()
  • Method Details

    • getCurrentUser

      @GetMapping("/me") public org.springframework.http.ResponseEntity<UserDTO> getCurrentUser(@RequestAttribute("userId") Long userId)
      Get current user information
    • getUserById

      @GetMapping("/{id}") @PreAuthorize("hasRole(\'ROLE_ADMIN\')") public org.springframework.http.ResponseEntity<UserDTO> getUserById(@PathVariable Long id)
      Get user by ID (admin only)
    • getAllUsers

      @GetMapping @PreAuthorize("hasRole(\'ROLE_ADMIN\')") public org.springframework.http.ResponseEntity<List<UserDTO>> getAllUsers()
      Get all users (admin only)
    • updateUser

      @PutMapping("/{id}") @PreAuthorize("@securityUtils.isCurrentUser(#id) or hasRole(\'ROLE_ADMIN\')") public org.springframework.http.ResponseEntity<UserDTO> updateUser(@PathVariable Long id, @Valid @RequestBody @Valid UserDTO userDTO)
      Update user information
    • changePassword

      @PostMapping("/{id}/change-password") @PreAuthorize("@securityUtils.isCurrentUser(#id) or hasRole(\'ROLE_ADMIN\')") public org.springframework.http.ResponseEntity<Void> changePassword(@PathVariable Long id, @RequestBody Map<String,String> passwordRequest)
      Change user password
    • deleteUser

      @DeleteMapping("/{id}") @PreAuthorize("hasRole(\'ROLE_ADMIN\')") public org.springframework.http.ResponseEntity<Void> deleteUser(@PathVariable Long id)
      Soft delete a user (admin only)
    • addRoleToUser

      @PostMapping("/{id}/roles") @PreAuthorize("hasRole(\'ROLE_ADMIN\')") public org.springframework.http.ResponseEntity<UserDTO> addRoleToUser(@PathVariable Long id, @RequestBody Map<String,String> roleRequest)
      Add role to user (admin only)
    • removeRoleFromUser

      @DeleteMapping("/{id}/roles/{roleName}") @PreAuthorize("hasRole(\'ROLE_ADMIN\')") public org.springframework.http.ResponseEntity<UserDTO> removeRoleFromUser(@PathVariable Long id, @PathVariable String roleName)
      Remove role from user (admin only)
    • getUserLoginHistory

      @GetMapping("/{id}/login-history") @PreAuthorize("@securityUtils.isCurrentUser(#id) or hasRole(\'ROLE_ADMIN\')") public org.springframework.http.ResponseEntity<List<UserLoginHistory>> getUserLoginHistory(@PathVariable Long id)
      Get user login history
    • getUserLoginHistoryRange

      @GetMapping("/{id}/login-history/range") @PreAuthorize("@securityUtils.isCurrentUser(#id) or hasRole(\'ROLE_ADMIN\')") public org.springframework.http.ResponseEntity<List<UserLoginHistory>> getUserLoginHistoryRange(@PathVariable Long id, @RequestParam String startDate, @RequestParam(required=false) String endDate)
      Get user login history for a specific date range
    • getActiveSessions

      @GetMapping("/{id}/active-sessions") @PreAuthorize("@securityUtils.isCurrentUser(#id) or hasRole(\'ROLE_ADMIN\')") public org.springframework.http.ResponseEntity<List<UserLoginHistory>> getActiveSessions(@PathVariable Long id)
      Get active sessions