@@ -29,7 +29,12 @@ public class ArtistService {
2929 private final ArtistRepository artistRepository ;
3030 private final GenreService genreService ;
3131 private final ArtistLikeRepository artistLikeRepository ;
32- private final Rq rq ;
32+
33+ @ Transactional (readOnly = true )
34+ public Artist findArtist (Long artistId ) {
35+ return artistRepository .findById (artistId )
36+ .orElseThrow (() -> new BusinessException (ArtistErrorCode .ARTIST_NOT_FOUND ));
37+ }
3338
3439 @ Transactional
3540 public int setArtist () {
@@ -131,9 +136,7 @@ public List<SearchResponse> search(String artistName) {
131136
132137 @ Transactional
133138 public void likeArtist (Long artistId , User user ) {
134- Artist artist = artistRepository .findById (artistId )
135- .orElseThrow (() -> new BusinessException (ArtistErrorCode .ARTIST_NOT_FOUND ));
136-
139+ Artist artist = findArtist (artistId );
137140 if (artistLikeRepository .existsByArtistAndUser (artist , user )) {
138141 throw new BusinessException (ArtistErrorCode .LIKES_ALREADY_EXISTS );
139142 }
@@ -143,8 +146,7 @@ public void likeArtist(Long artistId, User user) {
143146
144147 @ Transactional
145148 public void deleteLikeArtist (Long artistId , User user ) {
146- Artist artist = artistRepository .findById (artistId )
147- .orElseThrow (() -> new BusinessException (ArtistErrorCode .ARTIST_NOT_FOUND ));
149+ Artist artist = findArtist (artistId );
148150 ArtistLike likes = artistLikeRepository .findByArtistAndUser (artist , user )
149151 .orElseThrow (() -> new BusinessException (ArtistErrorCode .LIKES_NOT_FOUND ));
150152 artistLikeRepository .delete (likes );
0 commit comments