Package com.jangular.backend.controller

# Class UserController

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

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

## Constructor Summary

Constructors
Constructor
Description
`UserController()`

## Method Summary

Modifier and Type
Method
Description
`org.springframework.http.ResponseEntity<UserDTO>`
`addRoleToUser(Long id, Map<String,String> roleRequest)`
Add role to user (admin only)
`org.springframework.http.ResponseEntity<Void>`
`changePassword(Long id, Map<String,String> passwordRequest)`
Change user password
`org.springframework.http.ResponseEntity<Void>`
`deleteUser(Long id)`
Soft delete a user (admin only)
`org.springframework.http.ResponseEntity<List<UserLoginHistory>>`
`getActiveSessions(Long id)`
Get active sessions
`org.springframework.http.ResponseEntity<List<UserDTO>>`
`getAllUsers()`
Get all users (admin only)
`org.springframework.http.ResponseEntity<UserDTO>`
`getCurrentUser(Long userId)`
Get current user information
`org.springframework.http.ResponseEntity<UserDTO>`
`getUserById(Long id)`
Get user by ID (admin only)
`org.springframework.http.ResponseEntity<List<UserLoginHistory>>`
`getUserLoginHistory(Long id)`
Get user login history
`org.springframework.http.ResponseEntity<List<UserLoginHistory>>`
`getUserLoginHistoryRange(Long id, String startDate, String endDate)`
Get user login history for a specific date range
`org.springframework.http.ResponseEntity<UserDTO>`
`removeRoleFromUser(Long id, String roleName)`
Remove role from user (admin only)
`org.springframework.http.ResponseEntity<UserDTO>`
`updateUser(Long id, @Valid UserDTO userDTO)`
Update user information

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## 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