Package org.localify.repositories
Interface UserRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<User,,UUID> org.springframework.data.jpa.repository.JpaRepository<User,,UUID> org.springframework.data.repository.ListCrudRepository<User,,UUID> org.springframework.data.repository.ListPagingAndSortingRepository<User,,UUID> org.springframework.data.repository.PagingAndSortingRepository<User,,UUID> org.springframework.data.repository.query.QueryByExampleExecutor<User>,org.springframework.data.repository.Repository<User,UUID>
public interface UserRepository
extends org.springframework.data.jpa.repository.JpaRepository<User,UUID>
Repository for
User entities.-
Method Summary
Modifier and TypeMethodDescriptioncountByCreatedAtBefore(Instant createdAt) Counts the number of users created before a certain time.Counts the number of users who have opted in to emails.Counts the number of users with a verified email address.countByIsGuestFalseAndCreatedAtBetween(Instant start, Instant end) Counts the number of non-guest users created between two timestamps.countByIsGuestTrueAndCreatedAtBetween(Instant start, Instant end) Counts the number of guest users created between two timestamps.Counts the number of users with a Spotify ID.countByUpdatedAtBetween(Instant start, Instant end) Counts the number of users updated between two timestamps.Counts the number of users with an email address.Counts the number of users with both an email address and a Spotify ID.Finds all users who have opted in to emails and have an email address.findByAppleId(String appleId) Finds a user by their Apple Music ID.findByGoogleId(String googleId) Finds a user by their Google ID.Finds a user by their ID.findByNameNative(String name, int limit) Finds users by name using a native query.findBySpotifyId(String spotifyId) Finds a user by their Spotify ID.findByUserEmail(String email) Finds a user by their email address.findIdsByNameNative(String name, int limit) Finds user IDs by name using a native query.Finds the most recently created user.org.springframework.data.domain.Page<User>getAllOrderByAdminThenName(org.springframework.data.domain.Pageable pageable) Gets a page of all users, ordered by admin status and name.org.springframework.data.domain.Page<User>getAllOrderByAdminThenNameFiltered(org.springframework.data.domain.Pageable pageable, List<String> filters) Gets a page of users, filtered by role and ordered by admin status and name.getUserSeeds(UUID userId) Gets the seed artist IDs for a user.isUserGuest(UUID userId) Checks if a user is a guest.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
findBySpotifyId
Finds a user by their Spotify ID.- Parameters:
spotifyId- The Spotify ID.- Returns:
- An optional containing the user if found, otherwise empty.
-
findByGoogleId
Finds a user by their Google ID.- Parameters:
googleId- The Google ID.- Returns:
- An optional containing the user if found, otherwise empty.
-
findByAppleId
Finds a user by their Apple Music ID.- Parameters:
appleId- The Apple Music ID.- Returns:
- An optional containing the user if found, otherwise empty.
-
findById
Finds a user by their ID. -
isUserGuest
Checks if a user is a guest.- Parameters:
userId- The ID of the user.- Returns:
- true if the user is a guest, false otherwise.
-
findByUserEmail
@Query("select u from User u where u.userEmail ilike :email") Optional<User> findByUserEmail(String email) Finds a user by their email address.- Parameters:
email- The email address.- Returns:
- An optional containing the user if found, otherwise empty.
-
countByIsGuestFalseAndCreatedAtBetween
Counts the number of non-guest users created between two timestamps.- Parameters:
start- The start timestamp.end- The end timestamp.- Returns:
- A completable future containing the number of users.
-
countByIsGuestTrueAndCreatedAtBetween
Counts the number of guest users created between two timestamps.- Parameters:
start- The start timestamp.end- The end timestamp.- Returns:
- A completable future containing the number of users.
-
countByUpdatedAtBetween
Counts the number of users updated between two timestamps.- Parameters:
start- The start timestamp.end- The end timestamp.- Returns:
- A completable future containing the number of users.
-
countBySpotifyIdNotNull
Counts the number of users with a Spotify ID.- Returns:
- A completable future containing the number of users.
-
countByUserEmailNotNull
Counts the number of users with an email address.- Returns:
- A completable future containing the number of users.
-
countByUserEmailNotNullAndSpotifyIdNotNull
Integer countByUserEmailNotNullAndSpotifyIdNotNull()Counts the number of users with both an email address and a Spotify ID.- Returns:
- The number of users.
-
countByCreatedAtBefore
Counts the number of users created before a certain time.- Parameters:
createdAt- The timestamp to check against.- Returns:
- A completable future containing the number of users.
-
findTopByOrderByCreatedAt
User findTopByOrderByCreatedAt()Finds the most recently created user.- Returns:
- The user.
-
countByEmailOptInTrue
Counts the number of users who have opted in to emails.- Returns:
- A completable future containing the number of users.
-
countByEmailVerifiedTrue
Counts the number of users with a verified email address.- Returns:
- A completable future containing the number of users.
-
getAllOrderByAdminThenNameFiltered
@Query("select u from User u\nwhere (\'ADMIN\' in :filters and u.isAdmin = true) or\n (\'TEAM_MEMBER\' in :filters and u.isTeamMember = true) or\n (\'GUEST\' in :filters and u.isGuest = true) or\n (\'DISABLED\' in :filters and u.isDisabled = true)\norder by u.isAdmin desc, u.name\n") org.springframework.data.domain.Page<User> getAllOrderByAdminThenNameFiltered(org.springframework.data.domain.Pageable pageable, List<String> filters) Gets a page of users, filtered by role and ordered by admin status and name.- Parameters:
pageable- The pageable request.filters- The list of roles to filter by.- Returns:
- A page of users.
-
getAllOrderByAdminThenName
@Query("select u from User u\norder by u.isAdmin desc, u.name\n") org.springframework.data.domain.Page<User> getAllOrderByAdminThenName(org.springframework.data.domain.Pageable pageable) Gets a page of all users, ordered by admin status and name.- Parameters:
pageable- The pageable request.- Returns:
- A page of users.
-
getUserSeeds
@Query("select us.artist.id from UserSeedArtist us where us.user.id = :userId and us.blacklistedAt is null ") List<UUID> getUserSeeds(UUID userId) Gets the seed artist IDs for a user.- Parameters:
userId- The ID of the user.- Returns:
- A list of seed artist IDs.
-
findByNameNative
@Query(value="select * from users where name ilike concat(\'%\', :name, \'%\') limit :limit", nativeQuery=true) List<User> findByNameNative(String name, int limit) Finds users by name using a native query.- Parameters:
name- The name to search for.limit- The maximum number of results to return.- Returns:
- A list of users.
-
findIdsByNameNative
@Query(value="select id from users where name ilike concat(\'%\', :name, \'%\') limit :limit", nativeQuery=true) List<UUID> findIdsByNameNative(String name, int limit) Finds user IDs by name using a native query.- Parameters:
name- The name to search for.limit- The maximum number of results to return.- Returns:
- A list of user IDs.
-
findAllByEmailOptInTrueAndUserEmailNotNull
Finds all users who have opted in to emails and have an email address.- Returns:
- A list of users.
-