song 로그인
park 수정 삭제 없음
song 존재
@PostMapping("/s/board/{id}/delete")
public String delete(@PathVariable Long id, @AuthenticationPrincipal MyUserDetails myUserDetails) {
boardService.게시글삭제(id, myUserDetails.getUser().getId());
return "redirect:/";
}
@Transactional
public void 게시글삭제(Long id, Long userId) {
Board boardPS = boardRepository.findByIdFetchUser(id).orElseThrow(
() -> new Exception400("id", "게시글 아이디를 찾을 수 없습니다"));
if (boardPS.getUser().getId() != userId) {
throw new Exception403("권한이 없습니다");
}
try {
boardRepository.delete(boardPS);
} catch (Exception e) {
throw new Exception500("게시글 삭제 실패 : " + e.getMessage());
}
}
delete. update, insert -> 검증 후에 처리(앞에서 DB 조회 여부 확인해야함)
@Query("select b from Board b join fetch b.user where b.id = :id")
Optional<Board> findByIdFetchUser(@Param("id") Long id);
10번 삭제 후
ssar 로그인 -> 1번 삭제