Class UserService

java.lang.Object
com.equipmentrental.equipment_rental_system.service.UserService

@Service @Transactional(readOnly=true) public class UserService extends Object
Service layer for managing User entities. Handles CRUD operations and prevents deletion of users who have active bookings.
See Also:
  • Constructor Details

  • Method Details

    • findAll

      public List<User> findAll()
      Returns all registered users.
      Returns:
      list of all users
    • findById

      public User findById(Long userId)
      Finds a user by their ID.
      Parameters:
      userId - the ID of the user to find
      Returns:
      the user
      Throws:
      ResourceNotFoundException - if no user exists with the given ID
    • findByUsername

      public User findByUsername(String username)
      Finds a user by their unique username.
      Parameters:
      username - the username to search for
      Returns:
      the user
      Throws:
      ResourceNotFoundException - if no user exists with the given username
    • save

      @Transactional public User save(User user)
      Saves a new or updated user.
      Parameters:
      user - the user to save
      Returns:
      the saved user with generated ID (if new)
    • deleteById

      @Transactional public void deleteById(Long userId)
      Deletes a user if they have no active (confirmed) bookings.
      Parameters:
      userId - the ID of the user to delete
      Throws:
      ResourceNotFoundException - if no user exists with the given ID
      DeletionBlockedException - if the user has active bookings