Class UserService

java.lang.Object
me.josephsf.jobportaljosephsfeir.service.UserService

@Service public class UserService extends Object
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 Details

    • UserService

      public UserService(UserRepository userRepository)
      Constructs a new UserService with required dependencies.
      Parameters:
      userRepository - Repository for user data operations
  • Method Details

    • getAllUsers

      public List<User> getAllUsers()
      Retrieves all users.
      Returns:
      List of all user accounts
    • getUserById

      public User getUserById(String id)
      Retrieves a user by their ID.
      Parameters:
      id - The unique identifier of the user
      Returns:
      The user if found, null otherwise
    • getUserByUsername

      public User getUserByUsername(String username)
      Retrieves a user by their username.
      Parameters:
      username - The username to search for
      Returns:
      The user if found, null otherwise
    • getUserByEmail

      public User getUserByEmail(String email)
      Retrieves a user by their email address.
      Parameters:
      email - The email address to search for
      Returns:
      The user if found, null otherwise
    • saveUser

      public User saveUser(User user)
      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

      public User updateUser(String id, User userDetails)
      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 update
      userDetails - The user object containing updated information
      Returns:
      The updated user or null if the user is not found
    • deleteUser

      public void deleteUser(String id)
      Deletes a user by their ID.
      Parameters:
      id - The unique identifier of the user to delete
    • existsByUsername

      public boolean existsByUsername(String username)
      Checks if a username already exists in the system.
      Parameters:
      username - The username to check
      Returns:
      true if the username exists, false otherwise
    • existsByEmail

      public boolean existsByEmail(String email)
      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