From bd7beb6076c1cdb95d062a702b70eb57f6da2f78 Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Wed, 12 Oct 2022 16:27:50 +0900 Subject: [PATCH] =?UTF-8?q?#9=20feat:=20=EA=B2=8C=EC=8B=9C=EB=AC=BC=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=EC=A1=B0=ED=9A=8C=20API=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 | 21 ++++++++++++++---- .../server/board/dto/request/GetBoardReq.java | 19 ++++++++++++++++ .../server/board/service/BoardService.java | 7 +++--- .../board/service/BoardServiceImpl.java | 22 ++++++++++++++----- 4 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 server/src/main/java/com/yogit/server/board/dto/request/GetBoardReq.java diff --git a/server/src/main/java/com/yogit/server/board/controller/BoardController.java b/server/src/main/java/com/yogit/server/board/controller/BoardController.java index 8a72e0a..f10b32a 100644 --- a/server/src/main/java/com/yogit/server/board/controller/BoardController.java +++ b/server/src/main/java/com/yogit/server/board/controller/BoardController.java @@ -1,10 +1,7 @@ package com.yogit.server.board.controller; -import com.yogit.server.board.dto.request.CreateBoardReq; -import com.yogit.server.board.dto.request.DeleteBoardReq; -import com.yogit.server.board.dto.request.GetAllBoardsReq; -import com.yogit.server.board.dto.request.PatchBoardReq; +import com.yogit.server.board.dto.request.*; import com.yogit.server.board.dto.response.BoardRes; import com.yogit.server.board.service.BoardService; import com.yogit.server.global.dto.ApplicationResponse; @@ -94,4 +91,20 @@ public ApplicationResponse deleteBoard(@RequestBody @Validated DeleteB public ApplicationResponse> findAllBoards(@RequestBody @Validated GetAllBoardsReq getAllBoardsReq){ return boardService.findAllBoards(getAllBoardsReq); } + + + /** + * 게시글 상세 조회 + * @author 토마스 + */ + @ApiOperation(value = "게시글 상세 조회", notes = "게시물 id로 그룹 게시글 상세조회 요청.") + @ApiResponses({ + @ApiResponse(code= 201, message = "요청에 성공하였습니다."), + @ApiResponse(code= 404, message = "존재하지 않는 유저입니다."), + @ApiResponse(code = 4000 , message = "서버 오류입니다.") + }) + @PostMapping("/get/detail") + public ApplicationResponse findBoard(@RequestBody @Validated GetBoardReq getBoardReq){ + return boardService.findBoard(getBoardReq); + } } diff --git a/server/src/main/java/com/yogit/server/board/dto/request/GetBoardReq.java b/server/src/main/java/com/yogit/server/board/dto/request/GetBoardReq.java new file mode 100644 index 0000000..ec12df7 --- /dev/null +++ b/server/src/main/java/com/yogit/server/board/dto/request/GetBoardReq.java @@ -0,0 +1,19 @@ +package com.yogit.server.board.dto.request; + +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiParam; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class GetBoardReq { + + @ApiModelProperty(example = "1") + @ApiParam(value = "Board ID", required = true) + private Long boardId; + + @ApiModelProperty(example = "1") + @ApiParam(value = "유저 ID", required = true) + private Long userId; +} diff --git a/server/src/main/java/com/yogit/server/board/service/BoardService.java b/server/src/main/java/com/yogit/server/board/service/BoardService.java index ed0f585..4899ce1 100644 --- a/server/src/main/java/com/yogit/server/board/service/BoardService.java +++ b/server/src/main/java/com/yogit/server/board/service/BoardService.java @@ -1,9 +1,6 @@ package com.yogit.server.board.service; -import com.yogit.server.board.dto.request.CreateBoardReq; -import com.yogit.server.board.dto.request.DeleteBoardReq; -import com.yogit.server.board.dto.request.GetAllBoardsReq; -import com.yogit.server.board.dto.request.PatchBoardReq; +import com.yogit.server.board.dto.request.*; import com.yogit.server.board.dto.response.BoardRes; import com.yogit.server.global.dto.ApplicationResponse; @@ -18,4 +15,6 @@ public interface BoardService { ApplicationResponse deleteBoard(DeleteBoardReq deleteBoardReq); ApplicationResponse> findAllBoards(GetAllBoardsReq getAllBoardsReq); + + ApplicationResponse findBoard(GetBoardReq getBoardReq); } diff --git a/server/src/main/java/com/yogit/server/board/service/BoardServiceImpl.java b/server/src/main/java/com/yogit/server/board/service/BoardServiceImpl.java index d5b34ca..81d1627 100644 --- a/server/src/main/java/com/yogit/server/board/service/BoardServiceImpl.java +++ b/server/src/main/java/com/yogit/server/board/service/BoardServiceImpl.java @@ -1,9 +1,6 @@ package com.yogit.server.board.service; -import com.yogit.server.board.dto.request.CreateBoardReq; -import com.yogit.server.board.dto.request.DeleteBoardReq; -import com.yogit.server.board.dto.request.GetAllBoardsReq; -import com.yogit.server.board.dto.request.PatchBoardReq; +import com.yogit.server.board.dto.request.*; import com.yogit.server.board.dto.response.BoardRes; import com.yogit.server.board.entity.Board; import com.yogit.server.board.entity.BoardUser; @@ -120,7 +117,7 @@ public ApplicationResponse deleteBoard(DeleteBoardReq dto){ } - @Transactional(readOnly = false) + @Transactional(readOnly = true) @Override public ApplicationResponse> findAllBoards(GetAllBoardsReq dto){ int cursor = dto.getCursor(); @@ -137,4 +134,19 @@ public ApplicationResponse> findAllBoards(GetAllBoardsReq dto){ return ApplicationResponse.ok(boardsRes); } + + @Transactional(readOnly = true) + @Override + public ApplicationResponse findBoard(GetBoardReq dto){ + + User user = userRepository.findById(dto.getUserId()) + .orElseThrow(() -> new NotFoundUserException()); + + Board board = boardRepository.findBoardById(dto.getBoardId()) + .orElseThrow(() -> new NotFoundBoardException()); + + BoardRes boardRes = BoardRes.toDto(board); + return ApplicationResponse.ok(boardRes); + } + }