Skip to content

Commit

Permalink
fix: DELETE 매핑 수정 (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
YamYamee authored Aug 30, 2024
1 parent e42e32b commit 1a140f3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ public ApiResponse<GetPlaylistDTO> getAllMyPlaylist(@AuthUser Member member) {
}

@CrossOrigin
@DeleteMapping("/playlist/{playlistId}")
@DeleteMapping("/playlist/{playlistId}/cast/{castId}")
@Operation(summary = "플레이리스트에 남의 캐스트 삭제")
public ApiResponse<DeleteCastFromPlaylistDTO> deleteCastFromPlaylist(@PathVariable("playlistId") Long playlistId,
@RequestBody DeleteCastFromPlaylistDTO deleteCastFromPlaylistDTO) {
return ApiResponse.onSuccess(playlistService.deleteCast(deleteCastFromPlaylistDTO, playlistId));
public ApiResponse<DeleteCastFromPlaylistDTO> deleteCastFromPlaylist
(@PathVariable("playlistId") Long playlistId,
@PathVariable("castId") Long castId,
@AuthUser Member member) {
return ApiResponse.onSuccess(playlistService.deleteCast(playlistId, castId, member));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ public interface PlaylistService {

GetPlaylistDTO getAllMyPlaylists(Member member);

DeleteCastFromPlaylistDTO deleteCast(DeleteCastFromPlaylistDTO dto, Long playlistId);
DeleteCastFromPlaylistDTO deleteCast(Long playlistId, Long castId, Member member);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -196,12 +197,23 @@ public GetPlaylistDTO getAllMyPlaylists(Member member) {

@Override
@Transactional
public DeleteCastFromPlaylistDTO deleteCast(DeleteCastFromPlaylistDTO dto, Long playlistId) {
Cast cast = castRepository.findById(dto.getCastId()).orElseThrow(() -> new UserHandler(ErrorCode.CAST_NOT_FOUND));
public DeleteCastFromPlaylistDTO deleteCast(Long playlistId, Long castId, Member member) {
Cast cast = castRepository.findById(castId).orElseThrow(() -> new UserHandler(ErrorCode.CAST_NOT_FOUND));
Playlist playlist = playlistRepository.findById(playlistId).orElseThrow(() -> new UserHandler(ErrorCode.PLAYLIST_NOT_FOUND));

if(!Objects.equals(playlist.getMember().getId(), member.getId())){ // 본인의 플레이리스트가 아닌 경우
throw new UserHandler(ErrorCode.PLAYLIST_UNAUTHORIZED_ACCESS);
}

if(Objects.equals(cast.getMember().getId(), playlist.getMember().getId())) { // 본인이 만든 캐스트인 경우
throw new UserHandler(ErrorCode._BAD_REQUEST);
}

castPlaylistRepository.deleteByCastAndPlaylist(cast, playlist);

return dto;
return DeleteCastFromPlaylistDTO.builder()
.castId(castId)
.build();
}

@Override
Expand Down

0 comments on commit 1a140f3

Please sign in to comment.