Package com.jangular.backend.service

# Class UserService

java.lang.Object
com.jangular.backend.service.UserService

@Service public class UserService extends Object

## Constructor Summary

Constructors
Constructor
Description
`UserService()`

## Method Summary

Modifier and Type
Method
Description
`User`
`addRoleToUser(Long userId, RoleName roleName)`
Add role to user
`void`
`changePassword(Long userId, String newPassword)`
Change user password
`User`
`createUser(User user)`
Creates a new user with encoded password and default USER role
`boolean`
`existsByEmail(String email)`
Check if email already exists
`boolean`
`existsByUsername(String username)`
Check if username already exists
`List<User>`
`findAllActiveUsers()`
Get all active users
`Optional<User>`
`findByEmail(String email)`
Find user by email
`Optional<User>`
`findById(Long id)`
Find user by ID
`Optional<User>`
`findByUsername(String username)`
Find user by username
`Role`
`getDefaultRole()`
Get default role (ROLE_USER)
`void`
`incrementFailedAttempts(String username)`
Increment failed attempts
`void`
`lockUser(String username)`
Lock user account after max failed attempts
`User`
`removeRoleFromUser(Long userId, RoleName roleName)`
Remove role from user
`void`
`resetFailedAttempts(String username)`
Reset failed attempts
`void`
`softDeleteUser(Long userId)`
Soft delete a user
`void`
`unlockUser(String username)`
Unlock user account
`User`
`updateUser(User user)`
Updates a user's information

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

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

## Constructor Details

### UserService

public UserService()

## Method Details

### createUser

@Transactional public User createUser(User user)
Creates a new user with encoded password and default USER role

### findByUsername

public Optional<User> findByUsername(String username)
Find user by username

### findByEmail

public Optional<User> findByEmail(String email)
Find user by email

### findById

public Optional<User> findById(Long id)
Find user by ID

### findAllActiveUsers

public List<User> findAllActiveUsers()
Get all active users

### getDefaultRole

public Role getDefaultRole()
Get default role (ROLE_USER)

### updateUser

@Transactional public User updateUser(User user)
Updates a user's information

### softDeleteUser

@Transactional public void softDeleteUser(Long userId)
Soft delete a user

### changePassword

@Transactional public void changePassword(Long userId, String newPassword)
Change user password

### existsByUsername

public boolean existsByUsername(String username)
Check if username already exists

### existsByEmail

public boolean existsByEmail(String email)
Check if email already exists

### addRoleToUser

@Transactional public User addRoleToUser(Long userId, RoleName roleName)
Add role to user

### removeRoleFromUser

@Transactional public User removeRoleFromUser(Long userId, RoleName roleName)
Remove role from user

### lockUser

@Transactional public void lockUser(String username)
Lock user account after max failed attempts

### unlockUser

@Transactional public void unlockUser(String username)
Unlock user account

### incrementFailedAttempts

@Transactional public void incrementFailedAttempts(String username)
Increment failed attempts

### resetFailedAttempts

@Transactional public void resetFailedAttempts(String username)
Reset failed attempts