Skip to content

Commit

Permalink
fix: 아티스트 장르 저장 예외처리
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom committed Sep 26, 2024
1 parent 8c84b0b commit 6c22a08
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.dto.artist.param.ArtistNamesWithShowIdDomainParam;
import org.example.dto.artist.request.ArtistGenreDomainRequest;
import org.example.dto.artist.request.ArtistPaginationDomainRequest;
Expand All @@ -33,6 +34,7 @@
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Component
@RequiredArgsConstructor
public class ArtistUseCase {
Expand All @@ -51,10 +53,14 @@ public void save(ArtistWithGenreCreateDomainRequest request) {
Artist newArtist = artistGenre.toArtist();
artistRepository.save(newArtist);

Genre genre = genreRepository.findByName(artistGenre.genreName())
.orElseThrow(NoSuchElementException::new);
try {
Genre genre = genreRepository.findByName(artistGenre.genreName())
.orElseThrow(NoSuchElementException::new);

artistGenreRepository.save(newArtist.toArtistGenre(genre.getId()));
artistGenreRepository.save(newArtist.toArtistGenre(genre.getId()));
} catch (NoSuchElementException e) {
log.warn("해당하는 장르가 존재하지 않습니다.");
}
}
}

Expand Down

0 comments on commit 6c22a08

Please sign in to comment.