|
| 1 | +package com.ll.hfback.domain.board.comment.controller; |
| 2 | + |
| 3 | +import com.ll.hfback.domain.board.comment.entity.BoardComment; |
| 4 | +import com.ll.hfback.domain.board.comment.service.BoardCommentService; |
| 5 | +import com.ll.hfback.domain.board.notice.entity.Board; |
| 6 | +import com.ll.hfback.domain.board.notice.service.BoardService; |
| 7 | +import com.ll.hfback.domain.member.member.entity.Member; |
| 8 | +import com.ll.hfback.domain.member.member.service.MemberService; |
| 9 | +import com.ll.hfback.global.rsData.RsData; |
| 10 | +import com.ll.hfback.global.webMvc.LoginUser; |
| 11 | +import lombok.Data; |
| 12 | +import lombok.RequiredArgsConstructor; |
| 13 | +import org.springframework.security.access.prepost.PreAuthorize; |
| 14 | +import org.springframework.web.bind.annotation.*; |
| 15 | + |
| 16 | +import java.security.Principal; |
| 17 | +import java.sql.SQLOutput; |
| 18 | + |
| 19 | +@RequiredArgsConstructor |
| 20 | +@RestController |
| 21 | +@RequestMapping("/api/v1/boardComment") |
| 22 | +public class ApiV1BoardCommentController { |
| 23 | + |
| 24 | + private final BoardService boardService; |
| 25 | + private final BoardCommentService boardCommentService; |
| 26 | + private final MemberService memberService; |
| 27 | + |
| 28 | + //댓글 생성 dto RequestBody는 키벨류라서 dto로 키벨류 맞춰줘야 json 중첩오류가 안남 |
| 29 | + @Data |
| 30 | + public static class CreateBoardComment { |
| 31 | + String content; |
| 32 | + } |
| 33 | + |
| 34 | + //댓글 생성 |
| 35 | + @PreAuthorize("isAuthenticated") |
| 36 | + @PostMapping("/create/{boardId}") |
| 37 | + public RsData<BoardComment> create(@PathVariable("boardId") Long boardId, @RequestBody CreateBoardComment createBoardComment, @LoginUser Member member){ |
| 38 | + Board board = this.boardService.view(boardId); |
| 39 | + BoardComment boardComment = this.boardCommentService.create(boardId, createBoardComment.getContent(), member); |
| 40 | + System.out.println(boardComment); |
| 41 | + return new RsData<>("200","댓글을 성공적으로 생성했습니다.", boardComment); |
| 42 | + |
| 43 | + } |
| 44 | + //댓글 수정 dto |
| 45 | + @Data |
| 46 | + public static class ModifyBoardComment { |
| 47 | + String content; |
| 48 | + } |
| 49 | + |
| 50 | + //댓글 수정 |
| 51 | + @PreAuthorize("isAuthenticated()") |
| 52 | + @PatchMapping("/modify/{boardCommentId}") |
| 53 | + public RsData<BoardComment> modify(@PathVariable("boardCommentId")Long boardCommentId, @RequestBody ModifyBoardComment modifyBoardComment, Principal principal){ |
| 54 | + BoardComment boardComment = this.boardCommentService.getComment(boardCommentId); |
| 55 | + Member member = this.memberService.findByEmail(principal.getName()); |
| 56 | + BoardComment MdfBdComment = boardCommentService.modify(boardComment,modifyBoardComment.getContent(), member); |
| 57 | + return new RsData<>("200","댓글을 성공적으로 수정했습니다.",MdfBdComment); |
| 58 | + } |
| 59 | + |
| 60 | + |
| 61 | + //댓글 삭제 |
| 62 | + @PreAuthorize("isAuthenticated()") |
| 63 | + @DeleteMapping("/delete/{boardCommentId}") |
| 64 | + public RsData<Void> deleteBoardComment(@PathVariable("boardCommentId")Long boardCommentId,Principal principal){ |
| 65 | + BoardComment boardComment =this.boardCommentService.getComment(boardCommentId); |
| 66 | + Member member = this.memberService.findByEmail(principal.getName()); |
| 67 | + this.boardCommentService.delete(boardComment, member); |
| 68 | + return new RsData<>("200","댓글을 성공적으로 삭제했습니다."); |
| 69 | + } |
| 70 | +} |
0 commit comments