From 4f5d367e016330d711363b493d4112e4952bc464 Mon Sep 17 00:00:00 2001 From: yulmam Date: Wed, 17 Jul 2024 17:14:36 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat=20:=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20co?= =?UTF-8?q?ntroller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/BoardController.java | 147 ++++++++++++++++++ .../entity/dto/RequestBoardDetailDto.java | 2 + .../board/entity/dto/RequestCommentDto.java | 2 + .../entity/dto/ResponseBoardDetailDto.java | 2 + .../board/entity/dto/ResponseBoardDto.java | 2 + .../edufocus/board/entity/vo/Board.java | 2 + .../edufocus/board/entity/vo/Comment.java | 2 + .../edufocus/board/service/BoardService.java | 2 + .../board/service/BoardServiceImpl.java | 2 + 9 files changed, 163 insertions(+) create mode 100644 backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardDetailDto.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestCommentDto.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDto.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/board/service/BoardService.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java diff --git a/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java b/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java new file mode 100644 index 0000000..848335b --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java @@ -0,0 +1,147 @@ +package com.edufocus.edufocus.board.controller; + +import com.edufocus.edufocus.board.entity.dto.RequestBoardDetailDto; +import com.edufocus.edufocus.board.entity.dto.RequestCommentDto; +import com.edufocus.edufocus.board.entity.dto.ResponseBoardDetailDto; +import com.edufocus.edufocus.board.entity.dto.ResponseBoardDto; +import com.edufocus.edufocus.board.entity.vo.Comment; +import com.edufocus.edufocus.board.service.BoardService; +import jakarta.validation.constraints.Positive; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + + +/** + * @author Haneol Kim + */ +@RestController("/board") +public class BoardController { + + private final BoardService boardService; + + public BoardController(BoardService boardService){ + this.boardService = boardService; + } + + @GetMapping() + public ResponseEntity searchBoards( + Pageable pageable, + @RequestParam(value = "userId", required = true) int userId + ){ + + if(boardService.checkRegistration(userId, lectureId)){ + throw new RuntimeException(); + } + + List boards = boardService.findBoards(userId, category, lectureId); + + if(boards.isEmpty()){ + return ResponseEntity.noContent().build(); + } + + return ResponseEntity.ok(boards); + } + + @GetMapping(value = "/{boardId}") + public ResponseEntity getBoardDetail( + @PathVariable @Positive int boardId, + @RequestParam(value = "userId", required = true) @Positive int userId + ){ + ResponseBoardDetailDto responseBoardDetail = boardService.findBoardDetail(userId, boardId); + + return ResponseEntity.ok(responseBoardDetail); + } + + @PostMapping + public ResponseEntity addBoard( + @RequestBody RequestBoardDetailDto requestBoardDetailDto, + @RequestParam(value = "userId", required = true) @Positive int userId + ){ + if(boardService.checkRegistration(userId, requestBoardDetailDto.getLectureId())){ + throw new RuntimeException(); + } + + boardService.createBoard(userId, requestBoardDetailDto); + + return new ResponseEntity<>(HttpStatus.OK); + } + + @PutMapping(value = "/{boardId}") + public ResponseEntity updateBoard( + @PathVariable @Positive int boardId, + @RequestBody RequestBoardDetailDto requestBoardDetailDto, + @RequestParam(value = "userId", required = true) @Positive int userId + ){ + if(boardService.checkRegistration(userId, requestBoardDetailDto.getLectureId())){ + throw new RuntimeException(); + } + + boardService.createBoard(userId, requestBoardDetailDto); + + return new ResponseEntity<>(HttpStatus.OK); + } + + @DeleteMapping(value = "/{boardId}") + public ResponseEntity deleteBoard( + @PathVariable int boardId, + @RequestParam @Positive int userId + ){ + if(boardService.checkBoardOwner(userId, boardId)){ + throw new RuntimeException(); + } + + boardService.deleteBoard(boardId); + + return new ResponseEntity<>(HttpStatus.OK); + } + + @GetMapping(value = "/comment/{boardId}") + public ResponseEntity getComments( + @PathVariable @Positive int boardId, + @RequestParam @Positive int userId + ){ + List comments = boardService.findComments(userId, boardId); + + return ResponseEntity.ok(comments); + } + + @PostMapping(value = "/comment/{boardId}") + public ResponseEntity addComment( + @PathVariable @Positive int boardId, + @RequestParam int userId, + @RequestBody RequestCommentDto requestCommentDto + ){ + boardService.createComment(userId, boardId, requestCommentDto); + + return new ResponseEntity<>(HttpStatus.OK); + } + + @PutMapping(value = "/comment/{commentId}") + public ResponseEntity updateComment( + @RequestParam int userId, + @PathVariable @Positive int commentId, + @RequestBody RequestCommentDto requestCommentDto + ){ + boardService.checkCommentOwner(userId, commentId); + + boardService.updateComment(commentId, requestCommentDto); + + return new ResponseEntity<>(HttpStatus.OK); + } + + @DeleteMapping(value = "/comment/{commentId}") + public ResponseEntity deleteComment( + @PathVariable @Positive int commentId, + @RequestParam int userId + ){ + boardService.checkCommentOwner(userId, commentId); + + boardService.deleteComment(commentId); + + return new ResponseEntity<>(HttpStatus.OK); + } +} diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardDetailDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardDetailDto.java new file mode 100644 index 0000000..a88c1e0 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardDetailDto.java @@ -0,0 +1,2 @@ +package com.edufocus.edufocus.board.entity.dto;public class RequestBoartDetailDto { +} diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestCommentDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestCommentDto.java new file mode 100644 index 0000000..9a4ffcf --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestCommentDto.java @@ -0,0 +1,2 @@ +package com.edufocus.edufocus.board.entity.dto;public class RequestCommentDto { +} diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java new file mode 100644 index 0000000..383839a --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java @@ -0,0 +1,2 @@ +package com.edufocus.edufocus.board.entity.dto;public class ResponseBoardDetailDto { +} diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDto.java new file mode 100644 index 0000000..cb700e9 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDto.java @@ -0,0 +1,2 @@ +package com.edufocus.edufocus.board.entity.dto;public class ResponseBoardDto { +} diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java new file mode 100644 index 0000000..aca1d4d --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java @@ -0,0 +1,2 @@ +package com.edufocus.edufocus.board.entity.vo;public class Board { +} diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java new file mode 100644 index 0000000..92d3c3e --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java @@ -0,0 +1,2 @@ +package com.edufocus.edufocus.board.entity.vo;public class Comment { +} diff --git a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardService.java b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardService.java new file mode 100644 index 0000000..fad3c9d --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardService.java @@ -0,0 +1,2 @@ +package com.edufocus.edufocus.board.service;public interface BoardService { +} diff --git a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java new file mode 100644 index 0000000..7292811 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java @@ -0,0 +1,2 @@ +package com.edufocus.edufocus.board.service;public class BoardServiceImpl { +} From a02ee65a7eb0b940b983242abdd630085fd07673 Mon Sep 17 00:00:00 2001 From: yulmam Date: Thu, 18 Jul 2024 14:39:43 +0900 Subject: [PATCH 2/5] =?UTF-8?q?feat=20:=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/BoardController.java | 78 +++++------ .../entity/dto/RequestBoardDetailDto.java | 2 - .../board/entity/dto/RequestBoardDto.java | 14 ++ .../entity/dto/RequestBoardUpdateDto.java | 12 ++ .../board/entity/dto/RequestCommentDto.java | 4 +- .../entity/dto/ResponseBoardDetailDto.java | 21 ++- .../board/entity/dto/ResponseBoardDto.java | 7 +- .../edufocus/board/entity/vo/Board.java | 52 +++++++- .../edufocus/board/entity/vo/Comment.java | 40 +++++- .../board/repository/BoardRepository.java | 13 ++ .../board/repository/CommentRepository.java | 11 ++ .../edufocus/board/service/BoardService.java | 23 +++- .../board/service/BoardServiceImpl.java | 122 +++++++++++++++++- 13 files changed, 347 insertions(+), 52 deletions(-) delete mode 100644 backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardDetailDto.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardDto.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardUpdateDto.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/board/repository/BoardRepository.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/board/repository/CommentRepository.java diff --git a/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java b/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java index 848335b..a8a4db6 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java @@ -1,13 +1,13 @@ package com.edufocus.edufocus.board.controller; -import com.edufocus.edufocus.board.entity.dto.RequestBoardDetailDto; +import com.edufocus.edufocus.board.entity.dto.RequestBoardDto; +import com.edufocus.edufocus.board.entity.dto.RequestBoardUpdateDto; import com.edufocus.edufocus.board.entity.dto.RequestCommentDto; -import com.edufocus.edufocus.board.entity.dto.ResponseBoardDetailDto; -import com.edufocus.edufocus.board.entity.dto.ResponseBoardDto; +import com.edufocus.edufocus.board.entity.vo.Board; import com.edufocus.edufocus.board.entity.vo.Comment; import com.edufocus.edufocus.board.service.BoardService; +import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.constraints.Positive; -import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -29,15 +29,11 @@ public class BoardController { @GetMapping() public ResponseEntity searchBoards( - Pageable pageable, - @RequestParam(value = "userId", required = true) int userId + @RequestParam(value = "category", required = false, defaultValue = "announcement") String category, + @RequestParam(value = "lectureId", required = true) long lectureId, + @RequestParam(value = "pageNo", required = false, defaultValue = "0") int pageNo ){ - - if(boardService.checkRegistration(userId, lectureId)){ - throw new RuntimeException(); - } - - List boards = boardService.findBoards(userId, category, lectureId); + List boards = boardService.findBoards(pageNo, category, lectureId); if(boards.isEmpty()){ return ResponseEntity.noContent().build(); @@ -48,39 +44,35 @@ public class BoardController { @GetMapping(value = "/{boardId}") public ResponseEntity getBoardDetail( - @PathVariable @Positive int boardId, - @RequestParam(value = "userId", required = true) @Positive int userId + @PathVariable @Positive int boardId ){ - ResponseBoardDetailDto responseBoardDetail = boardService.findBoardDetail(userId, boardId); + Board responseBoardDetail = boardService.findBoardDetail(boardId); return ResponseEntity.ok(responseBoardDetail); } @PostMapping public ResponseEntity addBoard( - @RequestBody RequestBoardDetailDto requestBoardDetailDto, - @RequestParam(value = "userId", required = true) @Positive int userId + @RequestBody RequestBoardDto requestBoardDto, + HttpServletRequest request ){ - if(boardService.checkRegistration(userId, requestBoardDetailDto.getLectureId())){ - throw new RuntimeException(); - } - boardService.createBoard(userId, requestBoardDetailDto); + long userId = Long.parseLong(request.getHeader("Authentication")); + + boardService.createBoard(userId, requestBoardDto); return new ResponseEntity<>(HttpStatus.OK); } @PutMapping(value = "/{boardId}") public ResponseEntity updateBoard( - @PathVariable @Positive int boardId, - @RequestBody RequestBoardDetailDto requestBoardDetailDto, - @RequestParam(value = "userId", required = true) @Positive int userId + @PathVariable @Positive long boardId, + @RequestBody RequestBoardUpdateDto requestBoardUpdateDto, + HttpServletRequest request ){ - if(boardService.checkRegistration(userId, requestBoardDetailDto.getLectureId())){ - throw new RuntimeException(); - } + long userId = Long.parseLong(request.getHeader("Authentication")); - boardService.createBoard(userId, requestBoardDetailDto); + boardService.updateBoard(boardId, requestBoardUpdateDto); return new ResponseEntity<>(HttpStatus.OK); } @@ -88,12 +80,8 @@ public class BoardController { @DeleteMapping(value = "/{boardId}") public ResponseEntity deleteBoard( @PathVariable int boardId, - @RequestParam @Positive int userId + HttpServletRequest request ){ - if(boardService.checkBoardOwner(userId, boardId)){ - throw new RuntimeException(); - } - boardService.deleteBoard(boardId); return new ResponseEntity<>(HttpStatus.OK); @@ -102,8 +90,10 @@ public class BoardController { @GetMapping(value = "/comment/{boardId}") public ResponseEntity getComments( @PathVariable @Positive int boardId, - @RequestParam @Positive int userId + HttpServletRequest request ){ + long userId = Long.parseLong(request.getHeader("Authentication")); + List comments = boardService.findComments(userId, boardId); return ResponseEntity.ok(comments); @@ -112,23 +102,25 @@ public class BoardController { @PostMapping(value = "/comment/{boardId}") public ResponseEntity addComment( @PathVariable @Positive int boardId, - @RequestParam int userId, - @RequestBody RequestCommentDto requestCommentDto + @RequestParam String content, + HttpServletRequest request ){ - boardService.createComment(userId, boardId, requestCommentDto); + long userId = Long.parseLong(request.getHeader("Authentication")); + + boardService.createComment(userId, boardId, content); return new ResponseEntity<>(HttpStatus.OK); } @PutMapping(value = "/comment/{commentId}") public ResponseEntity updateComment( - @RequestParam int userId, @PathVariable @Positive int commentId, - @RequestBody RequestCommentDto requestCommentDto + @RequestParam String content, + HttpServletRequest request ){ - boardService.checkCommentOwner(userId, commentId); + long userId = Long.parseLong(request.getHeader("Authentication")); - boardService.updateComment(commentId, requestCommentDto); + boardService.updateComment(commentId, content); return new ResponseEntity<>(HttpStatus.OK); } @@ -136,9 +128,9 @@ public class BoardController { @DeleteMapping(value = "/comment/{commentId}") public ResponseEntity deleteComment( @PathVariable @Positive int commentId, - @RequestParam int userId + HttpServletRequest request ){ - boardService.checkCommentOwner(userId, commentId); + long userId = Long.parseLong(request.getHeader("Authentication")); boardService.deleteComment(commentId); diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardDetailDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardDetailDto.java deleted file mode 100644 index a88c1e0..0000000 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardDetailDto.java +++ /dev/null @@ -1,2 +0,0 @@ -package com.edufocus.edufocus.board.entity.dto;public class RequestBoartDetailDto { -} diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardDto.java new file mode 100644 index 0000000..ca59a75 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardDto.java @@ -0,0 +1,14 @@ +package com.edufocus.edufocus.board.entity.dto; + + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class RequestBoardDto { + private long lectureId; + private String title; + private String category; + private String content; +} diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardUpdateDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardUpdateDto.java new file mode 100644 index 0000000..58ff7a7 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardUpdateDto.java @@ -0,0 +1,12 @@ +package com.edufocus.edufocus.board.entity.dto; + + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class RequestBoardUpdateDto { + private String title; + private String content; +} diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestCommentDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestCommentDto.java index 9a4ffcf..6578cad 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestCommentDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestCommentDto.java @@ -1,2 +1,4 @@ -package com.edufocus.edufocus.board.entity.dto;public class RequestCommentDto { +package com.edufocus.edufocus.board.entity.dto; + +public class RequestCommentDto { } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java index 383839a..182a8cc 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java @@ -1,2 +1,21 @@ -package com.edufocus.edufocus.board.entity.dto;public class ResponseBoardDetailDto { +package com.edufocus.edufocus.board.entity.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +import java.time.LocalTime; + +@Builder +@Getter +@Setter +@AllArgsConstructor +public class ResponseBoardDetailDto { + private int id; + private String name; + private String content; + private int viewCount; + private LocalTime createdAt; + private LocalTime modifiedAt; } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDto.java index cb700e9..3d34b1a 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDto.java @@ -1,2 +1,7 @@ -package com.edufocus.edufocus.board.entity.dto;public class ResponseBoardDto { +package com.edufocus.edufocus.board.entity.dto; + +public class ResponseBoardDto { + private int id; + private String name; + private String title; } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java index aca1d4d..7f8de48 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java @@ -1,2 +1,52 @@ -package com.edufocus.edufocus.board.entity.vo;public class Board { +package com.edufocus.edufocus.board.entity.vo; + + +import com.edufocus.edufocus.lecture.entity.Lecture; +import com.edufocus.edufocus.user.model.entity.User; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.hibernate.annotations.CreationTimestamp; + +import java.time.LocalDate; +import java.util.Date; + +@Entity +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Setter +public class Board { + + @Id + @GeneratedValue + private long id; + + @Column(nullable = false) + private String title; + + @Column(nullable = false) + private String category; + + @Column(nullable = false) + private String content; + + @Column(nullable = true) + private int viewCount; + + @CreationTimestamp + LocalDate createdAt; + + @CreationTimestamp + LocalDate modifiedAt; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "lecture_id") + private Lecture lecture; } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java index 92d3c3e..c3059c9 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java @@ -1,2 +1,40 @@ -package com.edufocus.edufocus.board.entity.vo;public class Comment { +package com.edufocus.edufocus.board.entity.vo; + + +import com.edufocus.edufocus.user.model.entity.User; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.time.LocalTime; + +@Entity +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Setter +public class Comment { + @Id + @GeneratedValue + private long id; + @Column + private String content; + + @Column + private LocalTime createdAt; + + @Column + private LocalTime updatedAt; + + @ManyToOne + @JoinColumn(name = "user_id") + User user; + + @ManyToOne + @JoinColumn(name = "board_id") + Board board; + + } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/repository/BoardRepository.java b/backend/src/main/java/com/edufocus/edufocus/board/repository/BoardRepository.java new file mode 100644 index 0000000..2cdb7c1 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/board/repository/BoardRepository.java @@ -0,0 +1,13 @@ +package com.edufocus.edufocus.board.repository; + +import com.edufocus.edufocus.board.entity.vo.Board; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface BoardRepository extends JpaRepository { + Page findByLectureIdAndCategory(Long lectureId, String category, Pageable pageable); + +} diff --git a/backend/src/main/java/com/edufocus/edufocus/board/repository/CommentRepository.java b/backend/src/main/java/com/edufocus/edufocus/board/repository/CommentRepository.java new file mode 100644 index 0000000..9002ab8 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/board/repository/CommentRepository.java @@ -0,0 +1,11 @@ +package com.edufocus.edufocus.board.repository; + +import com.edufocus.edufocus.board.entity.vo.Comment; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface CommentRepository extends JpaRepository { + List findByBoardId(long boardId); + +} diff --git a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardService.java b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardService.java index fad3c9d..ac20175 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardService.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardService.java @@ -1,2 +1,23 @@ -package com.edufocus.edufocus.board.service;public interface BoardService { +package com.edufocus.edufocus.board.service; + +import com.edufocus.edufocus.board.entity.dto.RequestBoardDto; +import com.edufocus.edufocus.board.entity.dto.RequestBoardUpdateDto; +import com.edufocus.edufocus.board.entity.dto.RequestCommentDto; +import com.edufocus.edufocus.board.entity.vo.Board; +import com.edufocus.edufocus.board.entity.vo.Comment; + +import java.util.List; + +public interface BoardService { + + public List findBoards(int pageNo, String category, long lectureId); + public Board findBoardDetail(long boardId); + public void createBoard(long userId, RequestBoardDto requestBoardDto); + public void updateBoard(long boardId, RequestBoardUpdateDto requestBoardUpdateDto); + public void deleteBoard(long boardId); + public List findComments(long userId, long boardId); + public void createComment(long userId, long boardId, String content); + public void updateComment(long commentId, String content); + public void deleteComment(long commentId); + } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java index 7292811..308bd57 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java @@ -1,2 +1,122 @@ -package com.edufocus.edufocus.board.service;public class BoardServiceImpl { +package com.edufocus.edufocus.board.service; + + +import com.edufocus.edufocus.board.entity.dto.RequestBoardDto; +import com.edufocus.edufocus.board.entity.dto.RequestBoardUpdateDto; +import com.edufocus.edufocus.board.entity.dto.RequestCommentDto; +import com.edufocus.edufocus.board.entity.vo.Board; +import com.edufocus.edufocus.board.entity.vo.Comment; +import com.edufocus.edufocus.board.repository.BoardRepository; +import com.edufocus.edufocus.board.repository.CommentRepository; +import com.edufocus.edufocus.lecture.entity.Lecture; +import com.edufocus.edufocus.lecture.repository.LectureRepository; +import com.edufocus.edufocus.user.model.entity.User; +import com.edufocus.edufocus.user.model.repository.UserRepository; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class BoardServiceImpl implements BoardService { + + private static final int PAGE_SIZE = 10; + + private final UserRepository userRepository; + private final LectureRepository lectureRepository; + private final BoardRepository boardRepository; + private final CommentRepository commentRepository; + + public BoardServiceImpl(BoardRepository boardRepository, CommentRepository commentRepository, UserRepository userRepository, LectureRepository lectureRepository){ + this.boardRepository = boardRepository; + this.commentRepository = commentRepository; + this.userRepository = userRepository; + this.lectureRepository = lectureRepository; + } + + + @Override + public List findBoards(int pageNo, String category, long lectureId) { + Pageable pageable = PageRequest.of(pageNo, PAGE_SIZE); + Page boards = boardRepository.findByLectureIdAndCategory(lectureId, category, pageable); + return boards.getContent(); + } + + @Override + public Board findBoardDetail(long boardId) { + Board board = boardRepository.findById(boardId).get(); + return board; + } + + @Override + public void createBoard(long userId, RequestBoardDto requestBoardDto) { + User user = userRepository.findById(userId).get(); + Lecture lecture = lectureRepository.findById(requestBoardDto.getLectureId()).get(); + + Board board = Board.builder() + .title(requestBoardDto.getTitle()) + .category(requestBoardDto.getCategory()) + .content(requestBoardDto.getCategory()) + .user(user) + .lecture(lecture) + .build(); + + boardRepository.save(board); + } + + @Override + public void updateBoard(long boardId, RequestBoardUpdateDto requestBoardUpdateDto) { + Board board = boardRepository.findById(boardId).get(); + + board.setTitle(requestBoardUpdateDto.getTitle()); + board.setContent(requestBoardUpdateDto.getContent()); + + boardRepository.save(board); + } + + + @Override + public void deleteBoard(long boardId) { + Board board = boardRepository.findById(boardId).get(); + + boardRepository.delete(board); + } + + @Override + public List findComments(long userId, long boardId) { + return commentRepository.findByBoardId(boardId); + } + + @Override + public void createComment(long userId, long boardId, String content) { + User user = userRepository.findById(userId).get(); + Board board = boardRepository.findById(boardId).get(); + + Comment comment = Comment.builder() + .content(content) + .board(board) + .user(user) + .build(); + + commentRepository.save(comment); + } + + + + @Override + public void updateComment(long commentId, String content) { + Comment comment = commentRepository.findById(commentId).get(); + comment.setContent(content); + commentRepository.save(comment); + } + + @Override + public void deleteComment(long commentId) { + Comment comment = commentRepository.findById(commentId).get(); + commentRepository.delete(comment); + } + + } From 1549917d74bd612a1769b3e82977db41662d2b66 Mon Sep 17 00:00:00 2001 From: yulmam Date: Fri, 19 Jul 2024 12:58:12 +0900 Subject: [PATCH 3/5] =?UTF-8?q?feat=20:=20board=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=ED=8C=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edufocus/edufocus/board/entity/dto/RequestCommentDto.java | 4 +--- .../{ResponseBoardDto.java => ResponseBoardSummaryDto.java} | 0 .../edufocus/board/entity/dto/ResponseCommentDto.java | 2 ++ 3 files changed, 3 insertions(+), 3 deletions(-) rename backend/src/main/java/com/edufocus/edufocus/board/entity/dto/{ResponseBoardDto.java => ResponseBoardSummaryDto.java} (100%) create mode 100644 backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseCommentDto.java diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestCommentDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestCommentDto.java index 6578cad..9a4ffcf 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestCommentDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestCommentDto.java @@ -1,4 +1,2 @@ -package com.edufocus.edufocus.board.entity.dto; - -public class RequestCommentDto { +package com.edufocus.edufocus.board.entity.dto;public class RequestCommentDto { } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardSummaryDto.java similarity index 100% rename from backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDto.java rename to backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardSummaryDto.java diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseCommentDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseCommentDto.java new file mode 100644 index 0000000..8726e1c --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseCommentDto.java @@ -0,0 +1,2 @@ +package com.edufocus.edufocus.board.entity.dto;public class ResponseCommentDto { +} From cebabf77c3d208bf9c6e8dabbcd661feea63fe37 Mon Sep 17 00:00:00 2001 From: yulmam Date: Fri, 19 Jul 2024 13:07:22 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor=20:=20=EC=84=9C=EB=B9=84=EC=8A=A4?= =?UTF-8?q?=20=EB=A6=AC=ED=84=B4=EA=B0=92=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/BoardController.java | 69 ++++++++----------- .../board/entity/dto/RequestBoardDto.java | 1 + .../board/entity/dto/RequestCommentDto.java | 10 ++- .../entity/dto/ResponseBoardDetailDto.java | 3 +- .../entity/dto/ResponseBoardSummaryDto.java | 12 +++- .../board/entity/dto/ResponseCommentDto.java | 18 ++++- .../edufocus/board/entity/vo/Board.java | 41 ++++++++--- .../edufocus/board/entity/vo/Comment.java | 14 +++- .../board/repository/BoardRepository.java | 4 +- .../board/repository/CommentRepository.java | 3 + .../edufocus/board/service/BoardService.java | 24 ++++--- .../board/service/BoardServiceImpl.java | 66 ++++++++++-------- 12 files changed, 172 insertions(+), 93 deletions(-) diff --git a/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java b/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java index a8a4db6..d25d940 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java @@ -1,11 +1,10 @@ package com.edufocus.edufocus.board.controller; -import com.edufocus.edufocus.board.entity.dto.RequestBoardDto; -import com.edufocus.edufocus.board.entity.dto.RequestBoardUpdateDto; -import com.edufocus.edufocus.board.entity.dto.RequestCommentDto; +import com.edufocus.edufocus.board.entity.dto.*; import com.edufocus.edufocus.board.entity.vo.Board; import com.edufocus.edufocus.board.entity.vo.Comment; import com.edufocus.edufocus.board.service.BoardService; +import com.edufocus.edufocus.user.util.JWTUtil; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.constraints.Positive; import org.springframework.http.HttpStatus; @@ -18,13 +17,16 @@ import java.util.List; /** * @author Haneol Kim */ -@RestController("/board") +@RestController +@RequestMapping("/board") public class BoardController { + private final JWTUtil jwtUtil; private final BoardService boardService; - public BoardController(BoardService boardService){ + public BoardController(BoardService boardService, JWTUtil jwtUtil){ this.boardService = boardService; + this.jwtUtil = jwtUtil; } @GetMapping() @@ -33,22 +35,22 @@ public class BoardController { @RequestParam(value = "lectureId", required = true) long lectureId, @RequestParam(value = "pageNo", required = false, defaultValue = "0") int pageNo ){ - List boards = boardService.findBoards(pageNo, category, lectureId); + List boardSummaries = boardService.findBoards(pageNo, category, lectureId); - if(boards.isEmpty()){ - return ResponseEntity.noContent().build(); + if(boardSummaries.isEmpty()){ + return new ResponseEntity<>(HttpStatus.NO_CONTENT); } - return ResponseEntity.ok(boards); + return new ResponseEntity<>(boardSummaries, HttpStatus.OK); } @GetMapping(value = "/{boardId}") public ResponseEntity getBoardDetail( - @PathVariable @Positive int boardId + @PathVariable int boardId ){ - Board responseBoardDetail = boardService.findBoardDetail(boardId); + ResponseBoardDetailDto responseBoardDetailDto = boardService.findBoardDetail(boardId); - return ResponseEntity.ok(responseBoardDetail); + return new ResponseEntity<>(responseBoardDetailDto, HttpStatus.OK); } @PostMapping @@ -56,8 +58,8 @@ public class BoardController { @RequestBody RequestBoardDto requestBoardDto, HttpServletRequest request ){ - - long userId = Long.parseLong(request.getHeader("Authentication")); + String token = request.getHeader("Authorization"); + long userId = Long.parseLong(jwtUtil.getUserId(token)); boardService.createBoard(userId, requestBoardDto); @@ -66,12 +68,9 @@ public class BoardController { @PutMapping(value = "/{boardId}") public ResponseEntity updateBoard( - @PathVariable @Positive long boardId, - @RequestBody RequestBoardUpdateDto requestBoardUpdateDto, - HttpServletRequest request + @PathVariable long boardId, + @RequestBody RequestBoardUpdateDto requestBoardUpdateDto ){ - long userId = Long.parseLong(request.getHeader("Authentication")); - boardService.updateBoard(boardId, requestBoardUpdateDto); return new ResponseEntity<>(HttpStatus.OK); @@ -89,49 +88,41 @@ public class BoardController { @GetMapping(value = "/comment/{boardId}") public ResponseEntity getComments( - @PathVariable @Positive int boardId, - HttpServletRequest request + @PathVariable int boardId ){ - long userId = Long.parseLong(request.getHeader("Authentication")); + List comments = boardService.findComments(boardId); - List comments = boardService.findComments(userId, boardId); - - return ResponseEntity.ok(comments); + return new ResponseEntity<>(comments, HttpStatus.OK); } @PostMapping(value = "/comment/{boardId}") public ResponseEntity addComment( - @PathVariable @Positive int boardId, - @RequestParam String content, + @PathVariable int boardId, + @RequestBody RequestCommentDto requestCommentDto, HttpServletRequest request ){ - long userId = Long.parseLong(request.getHeader("Authentication")); + String token = request.getHeader("Authorization"); + long userId = Long.parseLong(jwtUtil.getUserId(token)); - boardService.createComment(userId, boardId, content); + boardService.createComment(userId, boardId, requestCommentDto); return new ResponseEntity<>(HttpStatus.OK); } @PutMapping(value = "/comment/{commentId}") public ResponseEntity updateComment( - @PathVariable @Positive int commentId, - @RequestParam String content, - HttpServletRequest request + @PathVariable int commentId, + @RequestBody RequestCommentDto requestCommentDto ){ - long userId = Long.parseLong(request.getHeader("Authentication")); - - boardService.updateComment(commentId, content); + boardService.updateComment(commentId, requestCommentDto); return new ResponseEntity<>(HttpStatus.OK); } @DeleteMapping(value = "/comment/{commentId}") public ResponseEntity deleteComment( - @PathVariable @Positive int commentId, - HttpServletRequest request + @PathVariable int commentId ){ - long userId = Long.parseLong(request.getHeader("Authentication")); - boardService.deleteComment(commentId); return new ResponseEntity<>(HttpStatus.OK); diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardDto.java index ca59a75..478017a 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestBoardDto.java @@ -1,6 +1,7 @@ package com.edufocus.edufocus.board.entity.dto; +import com.edufocus.edufocus.board.entity.vo.Board; import lombok.Getter; import lombok.Setter; diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestCommentDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestCommentDto.java index 9a4ffcf..4dfbd0b 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestCommentDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/RequestCommentDto.java @@ -1,2 +1,10 @@ -package com.edufocus.edufocus.board.entity.dto;public class RequestCommentDto { +package com.edufocus.edufocus.board.entity.dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class RequestCommentDto { + private String content; } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java index 182a8cc..8cf6bc7 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java @@ -12,8 +12,9 @@ import java.time.LocalTime; @Setter @AllArgsConstructor public class ResponseBoardDetailDto { - private int id; + private long id; private String name; + private String title; private String content; private int viewCount; private LocalTime createdAt; diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardSummaryDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardSummaryDto.java index 3d34b1a..d3e72a5 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardSummaryDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardSummaryDto.java @@ -1,7 +1,15 @@ package com.edufocus.edufocus.board.entity.dto; -public class ResponseBoardDto { - private int id; + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@Builder +@Getter +@Setter +public class ResponseBoardSummaryDto { + private long id; private String name; private String title; } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseCommentDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseCommentDto.java index 8726e1c..92156ce 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseCommentDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseCommentDto.java @@ -1,2 +1,18 @@ -package com.edufocus.edufocus.board.entity.dto;public class ResponseCommentDto { +package com.edufocus.edufocus.board.entity.dto; + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +import java.time.LocalTime; + +@Builder +@Getter +@Setter +public class ResponseCommentDto { + private long id; + private String name; + private String content; + private LocalTime createAt; + private LocalTime modifiedAt; } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java index 7f8de48..6272a17 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java @@ -1,23 +1,24 @@ package com.edufocus.edufocus.board.entity.vo; +import com.edufocus.edufocus.board.entity.dto.ResponseBoardDetailDto; +import com.edufocus.edufocus.board.entity.dto.ResponseBoardSummaryDto; import com.edufocus.edufocus.lecture.entity.Lecture; import com.edufocus.edufocus.user.model.entity.User; +import com.fasterxml.jackson.annotation.JsonAutoDetect; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.CreationTimestamp; -import java.time.LocalDate; -import java.util.Date; +import java.time.LocalTime; +import java.util.List; @Entity @Builder @NoArgsConstructor @AllArgsConstructor @Setter +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) public class Board { @Id @@ -37,10 +38,10 @@ public class Board { private int viewCount; @CreationTimestamp - LocalDate createdAt; + LocalTime createdAt; @CreationTimestamp - LocalDate modifiedAt; + LocalTime modifiedAt; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") @@ -49,4 +50,28 @@ public class Board { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "lecture_id") private Lecture lecture; + + + @OneToMany(mappedBy = "board") + private List comments; + + public ResponseBoardSummaryDto makeSummaryDto(){ + return ResponseBoardSummaryDto.builder() + .id(id) + .title(title) + .name(user.getUserId()) + .build(); + } + + public ResponseBoardDetailDto makeDetailDto(){ + return ResponseBoardDetailDto.builder() + .id(id) + .name(user.getEmail()) + .title(title) + .content(content) + .viewCount(viewCount) + .createdAt(createdAt) + .modifiedAt(modifiedAt) + .build(); + } } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java index c3059c9..90c7ebf 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java @@ -1,7 +1,9 @@ package com.edufocus.edufocus.board.entity.vo; +import com.edufocus.edufocus.board.entity.dto.ResponseCommentDto; import com.edufocus.edufocus.user.model.entity.User; +import com.fasterxml.jackson.annotation.JsonAutoDetect; import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Builder; @@ -15,6 +17,7 @@ import java.time.LocalTime; @NoArgsConstructor @AllArgsConstructor @Setter +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) public class Comment { @Id @GeneratedValue @@ -26,7 +29,7 @@ public class Comment { private LocalTime createdAt; @Column - private LocalTime updatedAt; + private LocalTime modifiedAt; @ManyToOne @JoinColumn(name = "user_id") @@ -36,5 +39,14 @@ public class Comment { @JoinColumn(name = "board_id") Board board; + public ResponseCommentDto makeCommentDto() { + return ResponseCommentDto.builder() + .id(id) + .name(user.getEmail()) + .content(content) + .createAt(createdAt) + .modifiedAt(modifiedAt) + .build(); + } } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/repository/BoardRepository.java b/backend/src/main/java/com/edufocus/edufocus/board/repository/BoardRepository.java index 2cdb7c1..beff8b3 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/repository/BoardRepository.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/repository/BoardRepository.java @@ -4,10 +4,12 @@ import com.edufocus.edufocus.board.entity.vo.Board; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; -import java.util.List; public interface BoardRepository extends JpaRepository { + + @Query("select b from Board b join fetch b.user where b.category =:category and b.lecture.id=:lectureId") Page findByLectureIdAndCategory(Long lectureId, String category, Pageable pageable); } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/repository/CommentRepository.java b/backend/src/main/java/com/edufocus/edufocus/board/repository/CommentRepository.java index 9002ab8..c877fd1 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/repository/CommentRepository.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/repository/CommentRepository.java @@ -2,10 +2,13 @@ package com.edufocus.edufocus.board.repository; import com.edufocus.edufocus.board.entity.vo.Comment; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import java.util.List; public interface CommentRepository extends JpaRepository { + + @Query("select c from Comment c join fetch c.user where c.board.id =:boardId") List findByBoardId(long boardId); } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardService.java b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardService.java index ac20175..f0d25f8 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardService.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardService.java @@ -1,23 +1,27 @@ package com.edufocus.edufocus.board.service; -import com.edufocus.edufocus.board.entity.dto.RequestBoardDto; -import com.edufocus.edufocus.board.entity.dto.RequestBoardUpdateDto; -import com.edufocus.edufocus.board.entity.dto.RequestCommentDto; -import com.edufocus.edufocus.board.entity.vo.Board; -import com.edufocus.edufocus.board.entity.vo.Comment; +import com.edufocus.edufocus.board.entity.dto.*; import java.util.List; public interface BoardService { - public List findBoards(int pageNo, String category, long lectureId); - public Board findBoardDetail(long boardId); public void createBoard(long userId, RequestBoardDto requestBoardDto); + + public List findBoards(int pageNo, String category, long lectureId); + + public ResponseBoardDetailDto findBoardDetail(long boardId); + public void updateBoard(long boardId, RequestBoardUpdateDto requestBoardUpdateDto); + public void deleteBoard(long boardId); - public List findComments(long userId, long boardId); - public void createComment(long userId, long boardId, String content); - public void updateComment(long commentId, String content); + + public void createComment(long userId, long boardId, RequestCommentDto requestCommentDto); + + public List findComments(long boardId); + + public void updateComment(long commentId, RequestCommentDto requestCommentDto); + public void deleteComment(long commentId); } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java index 308bd57..29c5006 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java @@ -1,9 +1,7 @@ package com.edufocus.edufocus.board.service; -import com.edufocus.edufocus.board.entity.dto.RequestBoardDto; -import com.edufocus.edufocus.board.entity.dto.RequestBoardUpdateDto; -import com.edufocus.edufocus.board.entity.dto.RequestCommentDto; +import com.edufocus.edufocus.board.entity.dto.*; import com.edufocus.edufocus.board.entity.vo.Board; import com.edufocus.edufocus.board.entity.vo.Comment; import com.edufocus.edufocus.board.repository.BoardRepository; @@ -12,22 +10,23 @@ import com.edufocus.edufocus.lecture.entity.Lecture; import com.edufocus.edufocus.lecture.repository.LectureRepository; import com.edufocus.edufocus.user.model.entity.User; import com.edufocus.edufocus.user.model.repository.UserRepository; -import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.stream.Collectors; @Service public class BoardServiceImpl implements BoardService { private static final int PAGE_SIZE = 10; - private final UserRepository userRepository; - private final LectureRepository lectureRepository; private final BoardRepository boardRepository; private final CommentRepository commentRepository; + private final UserRepository userRepository; + private final LectureRepository lectureRepository; public BoardServiceImpl(BoardRepository boardRepository, CommentRepository commentRepository, UserRepository userRepository, LectureRepository lectureRepository){ this.boardRepository = boardRepository; @@ -37,28 +36,32 @@ public class BoardServiceImpl implements BoardService { } - @Override - public List findBoards(int pageNo, String category, long lectureId) { + @Transactional + public List findBoards(int pageNo, String category, long lectureId) { Pageable pageable = PageRequest.of(pageNo, PAGE_SIZE); - Page boards = boardRepository.findByLectureIdAndCategory(lectureId, category, pageable); - return boards.getContent(); + + List boards = boardRepository.findByLectureIdAndCategory(lectureId, category, pageable).getContent(); + + return boards.stream().map(Board::makeSummaryDto) + .collect(Collectors.toList()); } - @Override - public Board findBoardDetail(long boardId) { - Board board = boardRepository.findById(boardId).get(); - return board; + @Transactional + public ResponseBoardDetailDto findBoardDetail(long boardId) { + return boardRepository.findById(boardId) + .orElseThrow() + .makeDetailDto(); } - @Override + @Transactional public void createBoard(long userId, RequestBoardDto requestBoardDto) { - User user = userRepository.findById(userId).get(); + User user = userRepository.findById(userId).orElseThrow(); Lecture lecture = lectureRepository.findById(requestBoardDto.getLectureId()).get(); Board board = Board.builder() .title(requestBoardDto.getTitle()) .category(requestBoardDto.getCategory()) - .content(requestBoardDto.getCategory()) + .content(requestBoardDto.getContent()) .user(user) .lecture(lecture) .build(); @@ -66,7 +69,7 @@ public class BoardServiceImpl implements BoardService { boardRepository.save(board); } - @Override + @Transactional public void updateBoard(long boardId, RequestBoardUpdateDto requestBoardUpdateDto) { Board board = boardRepository.findById(boardId).get(); @@ -77,25 +80,27 @@ public class BoardServiceImpl implements BoardService { } - @Override + @Transactional public void deleteBoard(long boardId) { Board board = boardRepository.findById(boardId).get(); boardRepository.delete(board); } - @Override - public List findComments(long userId, long boardId) { - return commentRepository.findByBoardId(boardId); + @Transactional + public List findComments(long boardId) { + return commentRepository.findByBoardId(boardId).stream() + .map(Comment::makeCommentDto) + .collect(Collectors.toList()); } - @Override - public void createComment(long userId, long boardId, String content) { + @Transactional + public void createComment(long userId, long boardId, RequestCommentDto requestCommentDto) { User user = userRepository.findById(userId).get(); Board board = boardRepository.findById(boardId).get(); Comment comment = Comment.builder() - .content(content) + .content(requestCommentDto.getContent()) .board(board) .user(user) .build(); @@ -105,16 +110,19 @@ public class BoardServiceImpl implements BoardService { - @Override - public void updateComment(long commentId, String content) { + @Transactional + public void updateComment(long commentId, RequestCommentDto requestCommentDto) { Comment comment = commentRepository.findById(commentId).get(); - comment.setContent(content); + + comment.setContent(requestCommentDto.getContent()); + commentRepository.save(comment); } - @Override + @Transactional public void deleteComment(long commentId) { Comment comment = commentRepository.findById(commentId).get(); + commentRepository.delete(comment); } From 459bf9725e17d2e6c617352efebfe5d75e0a8f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A0=95=EB=AF=BC?= Date: Fri, 19 Jul 2024 13:39:03 +0900 Subject: [PATCH 5/5] feat: q&a , answer --- .../qna/controller/QnaController.java | 70 ++++++++++++--- .../com/edufocus/edufocus/qna/entity/Qna.java | 8 +- .../edufocus/qna/entity/QnaRequestDto.java | 24 +++++ .../edufocus/qna/entity/QnaResponseDto.java | 38 ++++++++ .../qna/repository/QnaRepository.java | 7 +- .../edufocus/qna/service/QnaService.java | 13 ++- .../edufocus/qna/service/QnaServiceImpl.java | 89 ++++++++++++++++--- 7 files changed, 217 insertions(+), 32 deletions(-) create mode 100644 backend/src/main/java/com/edufocus/edufocus/qna/entity/QnaRequestDto.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/qna/entity/QnaResponseDto.java diff --git a/backend/src/main/java/com/edufocus/edufocus/qna/controller/QnaController.java b/backend/src/main/java/com/edufocus/edufocus/qna/controller/QnaController.java index 0a4c1d2..48cc08a 100644 --- a/backend/src/main/java/com/edufocus/edufocus/qna/controller/QnaController.java +++ b/backend/src/main/java/com/edufocus/edufocus/qna/controller/QnaController.java @@ -1,6 +1,8 @@ package com.edufocus.edufocus.qna.controller; import com.edufocus.edufocus.qna.entity.Qna; +import com.edufocus.edufocus.qna.entity.QnaRequestDto; +import com.edufocus.edufocus.qna.entity.QnaResponseDto; import com.edufocus.edufocus.qna.service.QnaService; import com.edufocus.edufocus.user.util.JWTUtil; import jakarta.servlet.http.HttpServletRequest; @@ -21,28 +23,71 @@ import java.util.List; public class QnaController { private final QnaService qnaService; private final JWTUtil jwtUtil; + private static int PAGE_SIZE=10; - @PostMapping - public ResponseEntity createQna(@RequestBody Qna qna , HttpServletRequest request) { + + @PostMapping("/{lecture_id}") + public ResponseEntity createQna(@PathVariable("lecture_id") Long lecture_id, @RequestBody QnaRequestDto qnaRequestDto , HttpServletRequest request) { try{ String token = request.getHeader("Authorization"); Long userId = Long.parseLong(jwtUtil.getUserId(token)); - qnaService.createQna(userId,qna); - return new ResponseEntity<>(qna, HttpStatus.CREATED); + QnaResponseDto qnaResponseDto= qnaService.createQna(userId,qnaRequestDto,lecture_id); + return new ResponseEntity<>( qnaResponseDto,HttpStatus.CREATED); }catch (Exception e){ throw new RuntimeException(e); } } + + @PostMapping({"/answer/create/{qna_id}"}) + public ResponseEntity createAnswer(@PathVariable("qna_id") Long qna_id, @RequestBody QnaRequestDto qnaRequestDto) + { + try { + QnaResponseDto responseDto = qnaService.createAnswer(qna_id,qnaRequestDto); + return new ResponseEntity<>(responseDto,HttpStatus.ACCEPTED); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + } + + @PutMapping({"/answer/update/{qna_id}"}) + public ResponseEntity updateAnswer(@PathVariable("qna_id") Long qna_id, @RequestBody QnaRequestDto qnaRequestDto) + { + try { + QnaResponseDto responseDto = qnaService.updateAnswer(qna_id,qnaRequestDto); + return new ResponseEntity<>(responseDto,HttpStatus.ACCEPTED); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + } + + @DeleteMapping("/answer/delete/{qna_id}") + public ResponseEntity deleteAnswer(@PathVariable("qna_id") Long qna_id) + { + try { + qnaService.deleteAnswer(qna_id); + return new ResponseEntity<>(HttpStatus.ACCEPTED); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + } + + @PutMapping("/{id}") - public ResponseEntity updateQna(@PathVariable Long id, @RequestBody Qna qna) { + public ResponseEntity updateQna(@PathVariable Long id, @RequestBody QnaRequestDto qnaRequestDto) { try{ - qnaService.updateQna(id,qna); - return new ResponseEntity<>(qna, HttpStatus.ACCEPTED); + QnaResponseDto qnaResponseDto= qnaService.updateQna(id,qnaRequestDto); + return new ResponseEntity<>(qnaResponseDto, HttpStatus.ACCEPTED); }catch (Exception e) { @@ -72,15 +117,12 @@ public class QnaController { } @GetMapping("/all/{id}") - public ResponseEntity> getAllQna(@PathVariable Long id) { + public ResponseEntity> getAllQna(@PathVariable Long id) { try { - System.out.print("@@@@@@@@@@@@@@@@@@@@@@@>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); - List qnaList= qnaService.getAllQnasByLecture(id); - for(Qna qna:qnaList) - { - System.out.print(qna.toString()); - } + + List qnaList= qnaService.getAllQnasByLecture(id,PAGE_SIZE); + return new ResponseEntity<>(qnaList, HttpStatus.ACCEPTED); } catch (SQLException e) { throw new RuntimeException(e); diff --git a/backend/src/main/java/com/edufocus/edufocus/qna/entity/Qna.java b/backend/src/main/java/com/edufocus/edufocus/qna/entity/Qna.java index 4451568..993484e 100644 --- a/backend/src/main/java/com/edufocus/edufocus/qna/entity/Qna.java +++ b/backend/src/main/java/com/edufocus/edufocus/qna/entity/Qna.java @@ -3,8 +3,7 @@ package com.edufocus.edufocus.qna.entity; import com.edufocus.edufocus.lecture.entity.Lecture; import com.edufocus.edufocus.user.model.entity.User; import jakarta.persistence.*; -import lombok.Getter; -import lombok.Setter; +import lombok.*; import org.checkerframework.checker.units.qual.C; import java.util.Date; @@ -12,6 +11,9 @@ import java.util.Date; @Entity @Getter @Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor public class Qna { // 연관관계 주인 @@ -42,6 +44,7 @@ public class Qna { private String answer; + private String name; @ManyToOne @JoinColumn(name= "id") private User user; @@ -51,4 +54,5 @@ public class Qna { private Lecture lecture; + } diff --git a/backend/src/main/java/com/edufocus/edufocus/qna/entity/QnaRequestDto.java b/backend/src/main/java/com/edufocus/edufocus/qna/entity/QnaRequestDto.java new file mode 100644 index 0000000..f73eeae --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/qna/entity/QnaRequestDto.java @@ -0,0 +1,24 @@ +package com.edufocus.edufocus.qna.entity; + +import jakarta.persistence.Column; +import lombok.*; + +@Getter +public class QnaRequestDto { + + + private String title; + private String content; + private String answer; + + public static Qna toEntity(QnaRequestDto qnaRequestDto) { + { + + return Qna.builder() + .content(qnaRequestDto.getContent()) + .title(qnaRequestDto.getTitle()) + .answer(qnaRequestDto.getAnswer()) + .build(); + } + } +} diff --git a/backend/src/main/java/com/edufocus/edufocus/qna/entity/QnaResponseDto.java b/backend/src/main/java/com/edufocus/edufocus/qna/entity/QnaResponseDto.java new file mode 100644 index 0000000..3ef0b6a --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/qna/entity/QnaResponseDto.java @@ -0,0 +1,38 @@ +package com.edufocus.edufocus.qna.entity; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.Date; + +@Getter + +@NoArgsConstructor +@AllArgsConstructor +public class QnaResponseDto { + + + private String title; + private String username; + private String content; + private Date createtAt; + private String answer; + public static QnaResponseDto toEntity(Qna qna) + { + return new QnaResponseDto( + + qna.getTitle(), + qna.getUser().getName(), + qna.getContent(), + qna.getCreatedAt(), + qna.getAnswer() + ); + } + + +} + + + diff --git a/backend/src/main/java/com/edufocus/edufocus/qna/repository/QnaRepository.java b/backend/src/main/java/com/edufocus/edufocus/qna/repository/QnaRepository.java index beeba54..d2cbf7f 100644 --- a/backend/src/main/java/com/edufocus/edufocus/qna/repository/QnaRepository.java +++ b/backend/src/main/java/com/edufocus/edufocus/qna/repository/QnaRepository.java @@ -1,6 +1,8 @@ package com.edufocus.edufocus.qna.repository; import com.edufocus.edufocus.qna.entity.Qna; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -11,8 +13,7 @@ import java.util.List; @Repository public interface QnaRepository extends JpaRepository { - @Query(value = "SELECT * FROM qna WHERE lecture_id = :lectureId", nativeQuery = true) - List findLecture(@Param("lectureId") Long lectureId); - + List findByLectureId(Long lecturerId); + Page findByLectureId(Long lectureId, Pageable pageable); } diff --git a/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaService.java b/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaService.java index 8acf0f5..2c84b6d 100644 --- a/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaService.java +++ b/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaService.java @@ -2,6 +2,8 @@ package com.edufocus.edufocus.qna.service; import com.edufocus.edufocus.lecture.entity.Lecture; import com.edufocus.edufocus.qna.entity.Qna; +import com.edufocus.edufocus.qna.entity.QnaRequestDto; +import com.edufocus.edufocus.qna.entity.QnaResponseDto; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -11,9 +13,14 @@ import java.util.List; @Service public interface QnaService { - void createQna(Long id,Qna qna) throws SQLException; - void updateQna(Long id,Qna qna) throws SQLException; + QnaResponseDto createQna(Long id, QnaRequestDto qnaRequestDto, Long lecture_id) throws SQLException; + QnaResponseDto updateQna(Long id,QnaRequestDto qnaRequestDto) throws SQLException; void deleteQna(Long id) throws SQLException; Qna getQna(Long id) throws SQLException; - List getAllQnasByLecture(Long lectureId) throws SQLException; + + List getAllQnasByLecture(Long lectureId,int pageNumber) throws SQLException; + QnaResponseDto createAnswer(Long id,QnaRequestDto qnaRequestDto) throws SQLException; + QnaResponseDto updateAnswer(Long id,QnaRequestDto qnaRequestDto) throws SQLException; + void deleteAnswer(Long id) throws SQLException; + } diff --git a/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaServiceImpl.java index 4e6cdc2..e53f585 100644 --- a/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaServiceImpl.java @@ -1,15 +1,28 @@ package com.edufocus.edufocus.qna.service; +import com.edufocus.edufocus.lecture.entity.Lecture; +import com.edufocus.edufocus.lecture.repository.LectureRepository; import com.edufocus.edufocus.qna.entity.Qna; +import com.edufocus.edufocus.qna.entity.QnaRequestDto; +import com.edufocus.edufocus.qna.entity.QnaResponseDto; import com.edufocus.edufocus.qna.repository.QnaRepository; +import com.edufocus.edufocus.user.model.entity.User; +import com.edufocus.edufocus.user.model.repository.UserRepository; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import lombok.Setter; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; +import java.sql.SQLException; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; @Service @Transactional @@ -17,25 +30,46 @@ import java.util.Optional; public class QnaServiceImpl implements QnaService{ private final QnaRepository qnaRepository; + private final LectureRepository lectureRepository; + private final UserRepository userRepository; + @Override - public void createQna(Long id,Qna qna) { + public QnaResponseDto createQna(Long id, QnaRequestDto qnaRequestDto, Long lecture_id) { - qna.setId(id); + Lecture lecture = lectureRepository.findById(lecture_id).orElse(null); + + User user = userRepository.findById(id).orElse(null); + + + + Qna qna = QnaRequestDto.toEntity(qnaRequestDto); + qna.setLecture(lecture); + qna.setUser(user); + + qna.setCreatedAt(new Date()); + qnaRepository.save(qna); - + return QnaResponseDto.toEntity(qna); } @Override - public void updateQna(Long id,Qna qna) { + public QnaResponseDto updateQna(Long id,QnaRequestDto qnaRequestDto) { - Optional findQna = qnaRepository.findById(id); + Qna findQna = qnaRepository.findById(id) + .orElseThrow(() -> new RuntimeException("QnA not found")); - qna.setModifiedAt(new Date()); - qnaRepository.save(qna); + findQna.setModifiedAt(new Date()); + findQna.setTitle(qnaRequestDto.getTitle()); + findQna.setContent(qnaRequestDto.getContent()); + + qnaRepository.save(findQna); + + + return QnaResponseDto.toEntity(findQna); } @@ -51,11 +85,46 @@ qnaRepository.deleteById(id); } @Override - public List getAllQnasByLecture(Long lectureId) { + public List getAllQnasByLecture(Long lectureId,int pageSize) + { + + Pageable pageable = PageRequest.of(0, pageSize); + + Page qnaPage = qnaRepository.findByLectureId(lectureId, pageable); - System.out.printf(lectureId+"!!!!!!!!!!!!!!!!!!!!!!"); - return qnaRepository.findLecture(lectureId); + return qnaPage.getContent().stream() + .map(QnaResponseDto::toEntity) + .collect(Collectors.toList()); } + + @Override + public QnaResponseDto createAnswer(Long id, QnaRequestDto qnaRequestDto) throws SQLException { + + Qna findQna = qnaRepository.findById(id).orElse(null); + findQna.setAnswer(qnaRequestDto.getAnswer()); + + qnaRepository.save(findQna); + + return QnaResponseDto.toEntity(findQna); + + } + + @Override + public QnaResponseDto updateAnswer(Long id, QnaRequestDto qnaRequestDto) throws SQLException { + + Qna findQna = qnaRepository.findById(id).orElse(null); + findQna.setAnswer(qnaRequestDto.getAnswer()); + + qnaRepository.save(findQna); + + return QnaResponseDto.toEntity(findQna); + } + + @Override + public void deleteAnswer(Long id) throws SQLException { + + qnaRepository.deleteById(id); + } }