Skip to content

Commit

Permalink
Merge pull request #89 from BDD-CLUB/feature/#46-순환_의존을_해결한다
Browse files Browse the repository at this point in the history
refactor: 자식 객체가 부모 객체의 Service에 의존하도록 변경
  • Loading branch information
lcqff authored Jan 27, 2025
2 parents 9184121 + 383c84c commit 1315052
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import MusicPlatform.domain.artist.service.ArtistService;
import MusicPlatform.domain.artist.service.dto.response.ArtistResponseDto;
import MusicPlatform.domain.track.entity.Track;
import MusicPlatform.domain.track.repository.TrackRepository;
import MusicPlatform.domain.track.service.dto.response.TrackBasicResponseDto;
import MusicPlatform.domain.track.service.TrackService;
import MusicPlatform.global.error.BusinessException;
import java.time.LocalDate;
import java.util.List;
Expand All @@ -30,7 +30,7 @@
@RequiredArgsConstructor
public class AlbumService {
private final AlbumRepository albumRepository;
private final TrackService trackService;
private final TrackRepository trackRepository;
private final ArtistService artistService;

@Transactional(readOnly = true)
Expand Down Expand Up @@ -91,7 +91,7 @@ public void deleteByUuid(String uuid) {
}

private AlbumFullResponseDto convertToDto(Album album, Pageable trackPageable) {
Page<Track> tracks = trackService.getAllByAlbum(album, trackPageable);
Page<Track> tracks = trackRepository.findAllByAlbum(album, trackPageable);
return AlbumFullResponseDto.builder()
.albumResponseDto(AlbumBasicResponseDto.from(album))
.trackResponseDtos(tracks.stream()
Expand Down
13 changes: 3 additions & 10 deletions src/main/java/MusicPlatform/domain/track/service/TrackService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package MusicPlatform.domain.track.service;

import static MusicPlatform.global.error.BusinessError.NOT_FOUND_ALBUM;
import static MusicPlatform.global.error.BusinessError.NOT_FOUND_TRACK;

import MusicPlatform.domain.album.entity.Album;
import MusicPlatform.domain.album.repository.AlbumRepository;
import MusicPlatform.domain.album.service.AlbumService;
import MusicPlatform.domain.artist.entity.Artist;
import MusicPlatform.domain.artist.service.ArtistService;
import MusicPlatform.domain.track.entity.Track;
Expand All @@ -27,7 +26,7 @@
@RequiredArgsConstructor
public class TrackService {
private final TrackRepository trackRepository;
private final AlbumRepository albumRepository;
private final AlbumService albumService;
private final ArtistService artistService;

@Transactional(readOnly = true)
Expand All @@ -36,14 +35,8 @@ public Track findByUuid(String uuid) {
new BusinessException(NOT_FOUND_TRACK));
}

@Transactional(readOnly = true)
public Page<Track> getAllByAlbum(Album album, Pageable pageable) {
return trackRepository.findAllByAlbum(album, pageable);
}

public void save(TrackRequestDto requestDto, String albumUuid) {
Album album = albumRepository.findByUuid(albumUuid)
.orElseThrow(() -> new BusinessException(NOT_FOUND_ALBUM));
Album album = albumService.getByUuid(albumUuid);
Track track = Track.builder()
.title(requestDto.title())
.lyric(requestDto.lyric())
Expand Down

0 comments on commit 1315052

Please sign in to comment.