11package com .back .web7_9_codecrete_be .domain .artists .repository ;
22
33import com .back .web7_9_codecrete_be .domain .artists .entity .Artist ;
4+ import com .back .web7_9_codecrete_be .domain .artists .entity .ArtistType ;
45import org .springframework .data .domain .Pageable ;
56import org .springframework .data .domain .Slice ;
67import org .springframework .data .jpa .repository .JpaRepository ;
1213
1314@ Repository
1415public interface ArtistRepository extends JpaRepository <Artist , Long > {
15- boolean existsBySpotifyArtistId (String spotifyArtistId );
16- java .util .Optional <Artist > findBySpotifyArtistId (String spotifyArtistId );
1716
1817 // 아티스트 상세 조회용 - artistGenres와 genre를 fetch join하여 N+1 문제 방지
1918 @ Query ("""
@@ -33,36 +32,40 @@ public interface ArtistRepository extends JpaRepository<Artist, Long> {
3332 boolean existsByArtistName (String artistName );
3433 boolean existsByNameKo (String nameKo );
3534
36- /**
37- * 같은 artistGroup인 아티스트들 조회 (관련 아티스트 추천용)
38- * artistGenres를 fetch join하여 N+1 문제 방지
39- */
35+ // 같은 artistGroup인 아티스트들 조회 (관련 아티스트 추천용) - artistGenres를 fetch join하여 N+1 문제 방지
4036 @ Query ("""
4137 SELECT DISTINCT a FROM Artist a
4238 LEFT JOIN FETCH a.artistGenres ag
4339 LEFT JOIN FETCH ag.genre
4440 WHERE a.artistGroup = :artistGroup AND a.id != :excludeId
4541 ORDER BY a.likeCount DESC, a.id ASC
4642 """ )
47- List <Artist > findByArtistGroupAndIdNot (@ org . springframework . data . repository . query . Param ("artistGroup" ) String artistGroup ,
48- @ org . springframework . data . repository . query . Param ("excludeId" ) long excludeId ,
43+ List <Artist > findByArtistGroupAndIdNot (@ Param ("artistGroup" ) String artistGroup ,
44+ @ Param ("excludeId" ) long excludeId ,
4945 Pageable pageable );
5046
51- /**
52- * 같은 genre인 아티스트들 조회 (관련 아티스트 추천용)
53- * artistGenres와 genre를 fetch join하여 N+1 문제 방지
54- */
47+ // 같은 genre인 아티스트들 조회 (관련 아티스트 추천용) - artistGenres와 genre를 fetch join하여 N+1 문제 방지
5548 @ Query ("""
5649 SELECT DISTINCT a FROM Artist a
5750 JOIN FETCH a.artistGenres ag
5851 JOIN FETCH ag.genre
5952 WHERE ag.genre.id = :genreId AND a.id != :excludeId
6053 ORDER BY a.likeCount DESC, a.id ASC
6154 """ )
62- List <Artist > findByGenreIdAndIdNot (@ org . springframework . data . repository . query . Param ("genreId" ) Long genreId ,
63- @ org . springframework . data . repository . query . Param ("excludeId" ) long excludeId ,
55+ List <Artist > findByGenreIdAndIdNot (@ Param ("genreId" ) Long genreId ,
56+ @ Param ("excludeId" ) long excludeId ,
6457 Pageable pageable );
6558
59+ // 장르별 아티스트 목록 조회 - artistGenres와 genre를 fetch join하여 N+1 문제 방지
60+ @ Query ("""
61+ SELECT DISTINCT a FROM Artist a
62+ JOIN FETCH a.artistGenres ag
63+ JOIN FETCH ag.genre g
64+ WHERE g.id = :genreId
65+ ORDER BY a.likeCount DESC, a.id ASC
66+ """ )
67+ List <Artist > findArtistsByGenreId (@ Param ("genreId" ) Long genreId );
68+
6669 List <Artist > findAllByArtistNameContainingIgnoreCaseOrNameKoContainingIgnoreCase (String artistName1 , String artistName2 );
6770
6871 Slice <Artist > findAllBy (Pageable pageable );
@@ -84,24 +87,21 @@ List<Artist> findByGenreIdAndIdNot(@org.springframework.data.repository.query.Pa
8487
8588 // 배치 조회: spotifyId 리스트로 존재하는 아티스트의 spotifyId만 반환
8689 @ Query ("SELECT a.spotifyArtistId FROM Artist a WHERE a.spotifyArtistId IN :spotifyIds" )
87- List <String > findSpotifyIdsBySpotifyIdsIn (@ org . springframework . data . repository . query . Param ("spotifyIds" ) List <String > spotifyIds );
90+ List <String > findSpotifyIdsBySpotifyIdsIn (@ Param ("spotifyIds" ) List <String > spotifyIds );
8891
8992 // 배치 조회: spotifyId 리스트로 존재하는 아티스트 전체 엔티티 반환 (Bulk 저장용)
9093 @ Query ("SELECT a FROM Artist a WHERE a.spotifyArtistId IN :spotifyIds" )
91- List <Artist > findBySpotifyArtistIdIn (@ org . springframework . data . repository . query . Param ("spotifyIds" ) List <String > spotifyIds );
94+ List <Artist > findBySpotifyArtistIdIn (@ Param ("spotifyIds" ) List <String > spotifyIds );
9295
93- /**
94- * 같은 artistType인 아티스트들 조회 (관련 아티스트 추천용, fallback)
95- * artistGenres를 fetch join하여 N+1 문제 방지
96- */
96+ // 같은 artistType인 아티스트들 조회 (관련 아티스트 추천용, fallback) - artistGenres를 fetch join하여 N+1 문제 방지
9797 @ Query ("""
9898 SELECT DISTINCT a FROM Artist a
9999 LEFT JOIN FETCH a.artistGenres ag
100100 LEFT JOIN FETCH ag.genre
101101 WHERE a.artistType = :artistType AND a.id != :excludeId
102102 ORDER BY a.likeCount DESC, a.id ASC
103103 """ )
104- List <Artist > findByArtistTypeAndIdNot (@ org . springframework . data . repository . query . Param ("artistType" ) com . back . web7_9_codecrete_be . domain . artists . entity . ArtistType artistType ,
105- @ org . springframework . data . repository . query . Param ("excludeId" ) long excludeId ,
104+ List <Artist > findByArtistTypeAndIdNot (@ Param ("artistType" ) ArtistType artistType ,
105+ @ Param ("excludeId" ) long excludeId ,
106106 Pageable pageable );
107107}
0 commit comments