Interface UserRepository

All Superinterfaces:
org.springframework.data.repository.CrudRepository<User,Long>, org.springframework.data.jpa.repository.JpaRepository<User,Long>, org.springframework.data.repository.ListCrudRepository<User,Long>, org.springframework.data.repository.ListPagingAndSortingRepository<User,Long>, org.springframework.data.repository.PagingAndSortingRepository<User,Long>, org.springframework.data.repository.query.QueryByExampleExecutor<User>, org.springframework.data.repository.Repository<User,Long>

@ConditionalOnProperty(name="lastshield.basicauth", havingValue="true") public interface UserRepository extends org.springframework.data.jpa.repository.JpaRepository<User,Long>
Repository interface for handling User-related database operations. This interface extends JpaRepository for CRUD operations on User entities and provides custom queries for fetching user data with specific roles or by specific fields.

The repository is conditionally activated based on the 'lastshield.basicauth' property. It is only available when this property is set to true.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks if a user exists with the given username.
    Retrieves a list of all users with the role 'USER', returning only the necessary fields in a UserDTO.
    Find a user by their unique ID.
    Find a user by their role.
    Find a user by their unique username.
    Find all users with the specified role.

    Methods inherited from interface org.springframework.data.repository.CrudRepository

    count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, save

    Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository

    deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlush

    Methods inherited from interface org.springframework.data.repository.ListCrudRepository

    findAll, findAllById, saveAll

    Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor

    count, exists, findAll, findBy, findOne
  • Method Details

    • findUserById

      Optional<User> findUserById(Long id)
      Find a user by their unique ID.
      Parameters:
      id - the unique identifier of the user.
      Returns:
      an Optional containing the User if found, empty if not.
    • findUserByUsername

      Optional<User> findUserByUsername(String username)
      Find a user by their unique username.
      Parameters:
      username - the username of the user.
      Returns:
      an Optional containing the User if found, empty if not.
    • existsUserByUsername

      boolean existsUserByUsername(String username)
      Checks if a user exists with the given username.
      Parameters:
      username - the username to check.
      Returns:
      true if a user with the given username exists, false otherwise.
    • findUserByRole

      Optional<User> findUserByRole(String role)
      Find a user by their role.
      Parameters:
      role - the role of the user.
      Returns:
      an Optional containing the User if found, empty if not.
    • findUsersByRole

      List<User> findUsersByRole(String role)
      Find all users with the specified role.
      Parameters:
      role - the role of the users.
      Returns:
      a List of Users with the specified role.
    • findAllUsersAsDTO

      @Query("SELECT new tech.lastbox.lastshield.basicauth.dto.UserDTO(u.id, u.name, u.username, u.role) FROM User u WHERE u.role = \'USER\'") List<UserDTO> findAllUsersAsDTO()
      Retrieves a list of all users with the role 'USER', returning only the necessary fields in a UserDTO.
      Returns:
      a list of UserDTO objects representing users with the 'USER' role.