Skip to content

Commit

Permalink
feat: #44 플레이리스트에 트랙 추가 시 중복 트랙 검사
Browse files Browse the repository at this point in the history
  • Loading branch information
dgh06175 committed Sep 26, 2024
1 parent 26c05d7 commit 57a7906
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,19 @@ public PlaylistResponse.PlayListId addTrackToPlaylist(Member member, Long playli
throw new RestApiException(PlaylistErrorCode.PLAYLIST_UPDATE_FORBIDDEN);
}

// TODO: playlist.getPlaylistTracks 를 가져와서 orderIndex 계산
// TODO: playlist.getPlaylistTracks 로 가져오기 (현재는 playlistTrackRepository.findAllByPlaylistIs(playlist) 로 대체)
List<PlaylistTrack> playlistTracks = playlistTrackRepository.findAllByPlaylistIs(playlist);

if (playlistTracks.stream().anyMatch(playlistTrack -> playlistTrack.getTrack().getId().equals(trackId.getTrackId()))) {
throw new RestApiException(PlaylistErrorCode.PLAYLIST_TRACK_DUPLICATE);
}

int nextOrderIndex = playlistTracks.isEmpty() ? 0 : playlistTracks.stream()
.mapToInt(PlaylistTrack::getOrderIndex)
.max()
.orElse(0) + 1;


PlaylistTrack playlistTrack = playlistMapper.toPlaylistTrack(playlist, track, nextOrderIndex);
playlistTrackRepository.save(playlistTrack);
return playlistMapper.toPlaylistId(playlistId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum PlaylistErrorCode implements ErrorCodeInterface{
PLAYLIST_UPDATE_FORBIDDEN("PLAYLIST003", "이 플레이리스트를 업데이트할 권한이 없습니다.", HttpStatus.FORBIDDEN),
PLAYLIST_TRACK_NOT_FOUND("PLAYLIST004", "플레이리스트에 해당 트랙이 존재하지 않습니다.", HttpStatus.NOT_FOUND),
PLAYLIST_TRACK_DELETE_FORBIDDEN("PLAYLIST005", "이 플레이리스트의 트랙을 삭제할 권한이 없습니다.", HttpStatus.FORBIDDEN),
PLAYLIST_TRACK_DUPLICATE("PLAYLIST006", "이미 추가된 트랙입니다.", HttpStatus.BAD_REQUEST),
;

private final String code;
Expand Down

0 comments on commit 57a7906

Please sign in to comment.