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 ;
78import org .springframework .data .jpa .repository .Query ;
9+ import org .springframework .data .repository .query .Param ;
810import org .springframework .stereotype .Repository ;
911
1012import java .util .List ;
1113
1214@ Repository
1315public interface ArtistRepository extends JpaRepository <Artist , Long > {
14- boolean existsBySpotifyArtistId (String spotifyArtistId );
15- java .util .Optional <Artist > findBySpotifyArtistId (String spotifyArtistId );
1616
1717 @ Query ("SELECT a FROM Artist a WHERE a.nameKo IS NULL ORDER BY a.id ASC" )
1818 List <Artist > findByNameKoIsNullOrderByIdAsc (Pageable pageable );
@@ -23,36 +23,40 @@ public interface ArtistRepository extends JpaRepository<Artist, Long> {
2323 boolean existsByArtistName (String artistName );
2424 boolean existsByNameKo (String nameKo );
2525
26- /**
27- * 같은 artistGroup인 아티스트들 조회 (관련 아티스트 추천용)
28- * artistGenres를 fetch join하여 N+1 문제 방지
29- */
26+ // 같은 artistGroup인 아티스트들 조회 (관련 아티스트 추천용) - artistGenres를 fetch join하여 N+1 문제 방지
3027 @ Query ("""
3128 SELECT DISTINCT a FROM Artist a
3229 LEFT JOIN FETCH a.artistGenres ag
3330 LEFT JOIN FETCH ag.genre
3431 WHERE a.artistGroup = :artistGroup AND a.id != :excludeId
3532 ORDER BY a.likeCount DESC, a.id ASC
3633 """ )
37- List <Artist > findByArtistGroupAndIdNot (@ org . springframework . data . repository . query . Param ("artistGroup" ) String artistGroup ,
38- @ org . springframework . data . repository . query . Param ("excludeId" ) long excludeId ,
34+ List <Artist > findByArtistGroupAndIdNot (@ Param ("artistGroup" ) String artistGroup ,
35+ @ Param ("excludeId" ) long excludeId ,
3936 Pageable pageable );
4037
41- /**
42- * 같은 genre인 아티스트들 조회 (관련 아티스트 추천용)
43- * artistGenres와 genre를 fetch join하여 N+1 문제 방지
44- */
38+ // 같은 genre인 아티스트들 조회 (관련 아티스트 추천용) - artistGenres와 genre를 fetch join하여 N+1 문제 방지
4539 @ Query ("""
4640 SELECT DISTINCT a FROM Artist a
4741 JOIN FETCH a.artistGenres ag
4842 JOIN FETCH ag.genre
4943 WHERE ag.genre.id = :genreId AND a.id != :excludeId
5044 ORDER BY a.likeCount DESC, a.id ASC
5145 """ )
52- List <Artist > findByGenreIdAndIdNot (@ org . springframework . data . repository . query . Param ("genreId" ) Long genreId ,
53- @ org . springframework . data . repository . query . Param ("excludeId" ) long excludeId ,
46+ List <Artist > findByGenreIdAndIdNot (@ Param ("genreId" ) Long genreId ,
47+ @ Param ("excludeId" ) long excludeId ,
5448 Pageable pageable );
5549
50+ // 장르별 아티스트 목록 조회 - artistGenres와 genre를 fetch join하여 N+1 문제 방지
51+ @ Query ("""
52+ SELECT DISTINCT a FROM Artist a
53+ JOIN FETCH a.artistGenres ag
54+ JOIN FETCH ag.genre g
55+ WHERE g.id = :genreId
56+ ORDER BY a.likeCount DESC, a.id ASC
57+ """ )
58+ List <Artist > findArtistsByGenreId (@ Param ("genreId" ) Long genreId );
59+
5660 List <Artist > findAllByArtistNameContainingIgnoreCaseOrNameKoContainingIgnoreCase (String artistName1 , String artistName2 );
5761
5862 Slice <Artist > findAllBy (Pageable pageable );
@@ -74,24 +78,21 @@ List<Artist> findByGenreIdAndIdNot(@org.springframework.data.repository.query.Pa
7478
7579 // 배치 조회: spotifyId 리스트로 존재하는 아티스트의 spotifyId만 반환
7680 @ Query ("SELECT a.spotifyArtistId FROM Artist a WHERE a.spotifyArtistId IN :spotifyIds" )
77- List <String > findSpotifyIdsBySpotifyIdsIn (@ org . springframework . data . repository . query . Param ("spotifyIds" ) List <String > spotifyIds );
81+ List <String > findSpotifyIdsBySpotifyIdsIn (@ Param ("spotifyIds" ) List <String > spotifyIds );
7882
7983 // 배치 조회: spotifyId 리스트로 존재하는 아티스트 전체 엔티티 반환 (Bulk 저장용)
8084 @ Query ("SELECT a FROM Artist a WHERE a.spotifyArtistId IN :spotifyIds" )
81- List <Artist > findBySpotifyArtistIdIn (@ org . springframework . data . repository . query . Param ("spotifyIds" ) List <String > spotifyIds );
85+ List <Artist > findBySpotifyArtistIdIn (@ Param ("spotifyIds" ) List <String > spotifyIds );
8286
83- /**
84- * 같은 artistType인 아티스트들 조회 (관련 아티스트 추천용, fallback)
85- * artistGenres를 fetch join하여 N+1 문제 방지
86- */
87+ // 같은 artistType인 아티스트들 조회 (관련 아티스트 추천용, fallback) - artistGenres를 fetch join하여 N+1 문제 방지
8788 @ Query ("""
8889 SELECT DISTINCT a FROM Artist a
8990 LEFT JOIN FETCH a.artistGenres ag
9091 LEFT JOIN FETCH ag.genre
9192 WHERE a.artistType = :artistType AND a.id != :excludeId
9293 ORDER BY a.likeCount DESC, a.id ASC
9394 """ )
94- List <Artist > findByArtistTypeAndIdNot (@ org . springframework . data . repository . query . Param ("artistType" ) com . back . web7_9_codecrete_be . domain . artists . entity . ArtistType artistType ,
95- @ org . springframework . data . repository . query . Param ("excludeId" ) long excludeId ,
95+ List <Artist > findByArtistTypeAndIdNot (@ Param ("artistType" ) ArtistType artistType ,
96+ @ Param ("excludeId" ) long excludeId ,
9697 Pageable pageable );
9798}
0 commit comments