Skip to content

Commit

Permalink
#9 feat: 게시물 상세조회 API구현
Browse files Browse the repository at this point in the history
  • Loading branch information
xhaktmchl committed Oct 12, 2022
1 parent 62aaa03 commit bd7beb6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -94,4 +91,20 @@ public ApplicationResponse<BoardRes> deleteBoard(@RequestBody @Validated DeleteB
public ApplicationResponse<List<BoardRes>> 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<BoardRes> findBoard(@RequestBody @Validated GetBoardReq getBoardReq){
return boardService.findBoard(getBoardReq);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -18,4 +15,6 @@ public interface BoardService {
ApplicationResponse<BoardRes> deleteBoard(DeleteBoardReq deleteBoardReq);

ApplicationResponse<List<BoardRes>> findAllBoards(GetAllBoardsReq getAllBoardsReq);

ApplicationResponse<BoardRes> findBoard(GetBoardReq getBoardReq);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -120,7 +117,7 @@ public ApplicationResponse<BoardRes> deleteBoard(DeleteBoardReq dto){
}


@Transactional(readOnly = false)
@Transactional(readOnly = true)
@Override
public ApplicationResponse<List<BoardRes>> findAllBoards(GetAllBoardsReq dto){
int cursor = dto.getCursor();
Expand All @@ -137,4 +134,19 @@ public ApplicationResponse<List<BoardRes>> findAllBoards(GetAllBoardsReq dto){
return ApplicationResponse.ok(boardsRes);
}


@Transactional(readOnly = true)
@Override
public ApplicationResponse<BoardRes> 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);
}

}

0 comments on commit bd7beb6

Please sign in to comment.