Class UserService
java.lang.Object
me.josephsf.jobportaljosephsfeir.service.UserService
Service class for managing user accounts in the Job Portal system.
This service provides methods for creating, retrieving, updating, and deleting user accounts. It interacts with the MongoDB database through the UserRepository and handles basic user management operations separate from authentication concerns.
- Since:
- 2025-05-15
-
Constructor Summary
ConstructorsConstructorDescriptionUserService(UserRepository userRepository) Constructs a new UserService with required dependencies. -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteUser(String id) Deletes a user by their ID.booleanexistsByEmail(String email) Checks if an email address already exists in the system.booleanexistsByUsername(String username) Checks if a username already exists in the system.Retrieves all users.getUserByEmail(String email) Retrieves a user by their email address.getUserById(String id) Retrieves a user by their ID.getUserByUsername(String username) Retrieves a user by their username.Saves a user to the database.updateUser(String id, User userDetails) Updates an existing user's information.
-
Constructor Details
-
UserService
Constructs a new UserService with required dependencies.- Parameters:
userRepository- Repository for user data operations
-
-
Method Details
-
getAllUsers
Retrieves all users.- Returns:
- List of all user accounts
-
getUserById
Retrieves a user by their ID.- Parameters:
id- The unique identifier of the user- Returns:
- The user if found, null otherwise
-
getUserByUsername
Retrieves a user by their username.- Parameters:
username- The username to search for- Returns:
- The user if found, null otherwise
-
getUserByEmail
Retrieves a user by their email address.- Parameters:
email- The email address to search for- Returns:
- The user if found, null otherwise
-
saveUser
Saves a user to the database. Can be used for both creating new users and updating existing ones.- Parameters:
user- The user to save- Returns:
- The saved user with updated metadata
-
updateUser
Updates an existing user's information. Does not update password - separate methods should be used for that.- Parameters:
id- The unique identifier of the user to updateuserDetails- The user object containing updated information- Returns:
- The updated user or null if the user is not found
-
deleteUser
Deletes a user by their ID.- Parameters:
id- The unique identifier of the user to delete
-
existsByUsername
Checks if a username already exists in the system.- Parameters:
username- The username to check- Returns:
- true if the username exists, false otherwise
-
existsByEmail
Checks if an email address already exists in the system.- Parameters:
email- The email address to check- Returns:
- true if the email exists, false otherwise
-