Interface SongRepository

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

public interface SongRepository extends org.springframework.data.jpa.repository.JpaRepository<Song,UUID>
Repository for Song entities.
  • Method Summary

    Modifier and Type
    Method
    Description
    Finds a song by its ISRC.
    Finds a song by its Spotify ID.
    getSongs(UUID artistId)
    Gets all songs for an artist.
    Gets a list of songs ordered by artist popularity.
    Gets the top song for an artist.
    getTopSongs(UUID artistId, org.springframework.data.domain.Pageable pageable)
    Gets the top songs for an artist.

    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

    • findBySpotifyId

      Song findBySpotifyId(String spotifyId)
      Finds a song by its Spotify ID.
      Parameters:
      spotifyId - The Spotify ID.
      Returns:
      The song.
    • findByIsrc

      Song findByIsrc(String isrc)
      Finds a song by its ISRC.
      Parameters:
      isrc - The ISRC.
      Returns:
      The song.
    • getTopSongForArtist

      @Query(value="select s.* from artist_songs ars\njoin songs s on ars.song_id = s.id\nwhere artist_id = :artistId\norder by spotify_popularity desc fetch first 1 row only\n", nativeQuery=true) Optional<Song> getTopSongForArtist(@Param("artistId") UUID artistId)
      Gets the top song for an artist.
      Parameters:
      artistId - The ID of the artist.
      Returns:
      An optional containing the top song if found, otherwise empty.
    • getTopSongs

      @Query("select az.song from ArtistSong as az where az.artist.id = :artistId and az.song.spotifyId is not null order by az.song.spotifyPopularity desc nulls last") List<Song> getTopSongs(UUID artistId, org.springframework.data.domain.Pageable pageable)
      Gets the top songs for an artist.
      Parameters:
      artistId - The ID of the artist.
      pageable - The pageable request.
      Returns:
      A list of songs.
    • getSongs

      @Query("select a.song from ArtistSong a where a.artist.id = :artistId ") List<Song> getSongs(UUID artistId)
      Gets all songs for an artist.
      Parameters:
      artistId - The ID of the artist.
      Returns:
      A list of songs.
    • getSongsOrderByArtistPopularity

      @Query(value="select s.* from songs s\njoin artist_songs asg on s.id = asg.song_id\njoin artists a on asg.artist_id = a.id\norder by a.spotify_popularity desc\nlimit :limit\n", nativeQuery=true) List<Song> getSongsOrderByArtistPopularity(int limit)
      Gets a list of songs ordered by artist popularity.
      Parameters:
      limit - The maximum number of results to return.
      Returns:
      A list of songs.