-
Notifications
You must be signed in to change notification settings - Fork 2
[REFACTOR] PlayingService 연주 생명주기별 책임 분리 #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PlayingFileService의 책임 범위가 이름에서 조금 넓게 느껴져 확인 차 코멘트 드립니다! 현재 PlayingFileService는 createRecordingUploadUrl()을 통한 녹음 파일 Presigned Upload URL 발급만 담당하고 있고, 조회 시 필요한 Presigned Download URL 생성은 PlayingQueryService, 업로드된 녹음 파일 검증은 PlayingService에서 처리하고 있는 것으로 확인했습니다~ 현재처럼 유스케이스별로 책임을 나누는 구조 자체는 괜찮아 보이는데, PlayingFileService라는 이름만 보면 Playing 도메인의 파일 관련 처리를 전반적으로 담당하는 서비스처럼 읽힐 수도 있을 것 같아요. 녹음 업로드 URL 발급만 담당하도록 의도한 서비스라면 PlayingRecordingFileService 또는 역할이 조금 더 드러나는 이름을 고려해봐도 좋을 것 같습니다! (꼭 고칠 필요 X... p3 정도로 봐주면 됨!) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package com.mr.domain.playing.service; | ||
|
|
||
| import com.mr.domain.playing.dto.req.RecordingUploadUrlRequest; | ||
| import com.mr.domain.playing.dto.res.RecordingUploadUrlResponse; | ||
| import com.mr.domain.playing.entity.Playing; | ||
| import com.mr.domain.playing.exception.PlayingErrorStatus; | ||
| import com.mr.domain.playing.repository.PlayingRepository; | ||
| import com.mr.global.apipayload.exception.GeneralException; | ||
| import com.mr.global.file.s3.enums.S3FileType; | ||
| import com.mr.global.file.s3.service.S3FileService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class PlayingFileService { | ||
|
|
||
| private final PlayingRepository playingRepository; | ||
| private final S3FileService s3FileService; | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public RecordingUploadUrlResponse createRecordingUploadUrl( | ||
| Long userId, Long playingId, RecordingUploadUrlRequest request | ||
| ) { | ||
| validatePlayingId(playingId); | ||
|
|
||
| Playing playing = playingRepository.findByIdAndDeletedAtIsNull(playingId) | ||
| .orElseThrow(() -> new GeneralException(PlayingErrorStatus.PLAYING_NOT_FOUND)); | ||
|
|
||
| playing.validatePlayingOwner(userId); | ||
| playing.validateInProgress(); | ||
|
|
||
| return RecordingUploadUrlResponse.from(s3FileService.createPresignedUpload( | ||
| userId, S3FileType.RECORDING, request.toCommand()) | ||
| ); | ||
| } | ||
|
|
||
| private void validatePlayingId(Long playingId) { | ||
| if (playingId == null || playingId < 1) { | ||
| throw new GeneralException(PlayingErrorStatus.INVALID_PLAYING_ID); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| package com.mr.domain.playing.service; | ||
|
|
||
| import com.mr.domain.analysis.service.AnalysisBarCalculator; | ||
| import com.mr.domain.backingtrack.entity.BackingTrack; | ||
| import com.mr.domain.playing.dto.res.AnalysisContextResponse; | ||
| import com.mr.domain.playing.dto.res.PlayingDetailResponse; | ||
| import com.mr.domain.playing.entity.Playing; | ||
| import com.mr.domain.playing.exception.PlayingErrorStatus; | ||
| import com.mr.domain.playing.repository.PlayingRepository; | ||
| import com.mr.global.apipayload.exception.GeneralException; | ||
| import com.mr.global.file.s3.enums.S3FileType; | ||
| import com.mr.global.file.s3.service.S3FileService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class PlayingQueryService { | ||
|
|
||
| private final PlayingRepository playingRepository; | ||
| private final S3FileService s3FileService; | ||
| private final AnalysisBarCalculator analysisBarCalculator; | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public PlayingDetailResponse getPlayingDetail(Long userId, Long playingId) { | ||
| validatePlayingId(playingId); | ||
|
|
||
| Playing playing = playingRepository.findByIdWithBackingTrack(playingId) | ||
| .orElseThrow(() -> new GeneralException(PlayingErrorStatus.PLAYING_NOT_FOUND)); | ||
|
|
||
| playing.validatePlayingOwner(userId); | ||
| playing.validateCompleted(); | ||
|
|
||
| String recordingFileUrl = | ||
| s3FileService.createPresignedDownload( | ||
| userId, | ||
| S3FileType.RECORDING, | ||
| playing.getRecordingObjectKey() | ||
| ); | ||
|
|
||
| return PlayingDetailResponse.from(playing, recordingFileUrl); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public AnalysisContextResponse getAnalysisContext(Long userId, Long playingId) { | ||
| validatePlayingId(playingId); | ||
|
|
||
| Playing playing = playingRepository.findByIdWithBackingTrack(playingId) | ||
| .orElseThrow(() -> new GeneralException(PlayingErrorStatus.PLAYING_NOT_FOUND)); | ||
|
|
||
| playing.validatePlayingOwner(userId); | ||
| playing.validateCompleted(); | ||
| if (playing.getBackingTrack() == null) { | ||
| throw new GeneralException(PlayingErrorStatus.BACKING_TRACK_NOT_FOUND); | ||
| } | ||
|
|
||
| String recordingFileUrl = | ||
| s3FileService.createPresignedDownload( | ||
| userId, | ||
| S3FileType.RECORDING, | ||
| playing.getRecordingObjectKey() | ||
| ); | ||
|
|
||
| BackingTrack backingTrack = playing.getBackingTrack(); | ||
|
|
||
| String backingTrackAudioFileUrl = null; | ||
|
|
||
| if (backingTrack.getAudioObjectKey() != null | ||
| && !backingTrack.getAudioObjectKey().isBlank()) { | ||
|
|
||
| backingTrackAudioFileUrl = | ||
| s3FileService.createPresignedDownload( | ||
| backingTrack.getUser().getUserId(), | ||
| S3FileType.BACKING_TRACK, | ||
| backingTrack.getAudioObjectKey() | ||
| ); | ||
| } | ||
|
|
||
| int totalBars = analysisBarCalculator.calculate(playing).totalBars(); | ||
| return AnalysisContextResponse.from(playing, totalBars, recordingFileUrl, backingTrackAudioFileUrl); | ||
| } | ||
|
|
||
| private void validatePlayingId(Long playingId) { | ||
| if (playingId == null || playingId < 1) { | ||
| throw new GeneralException(PlayingErrorStatus.INVALID_PLAYING_ID); | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.