diff --git a/src/main/java/com/haedal/haedalweb/config/SecurityConfig.java b/src/main/java/com/haedal/haedalweb/config/SecurityConfig.java index 0add183..08dc075 100644 --- a/src/main/java/com/haedal/haedalweb/config/SecurityConfig.java +++ b/src/main/java/com/haedal/haedalweb/config/SecurityConfig.java @@ -77,7 +77,7 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { .requestMatchers("/admin/**").hasAnyRole("WEB_MASTER", "ADMIN") .requestMatchers("/boards/generate-presigned-url").hasAnyRole("WEB_MASTER", "ADMIN", "TEAM_LEADER") .requestMatchers(HttpMethod.POST, "/activities/{activityId}/boards").hasAnyRole("WEB_MASTER", "ADMIN", "TEAM_LEADER") - .requestMatchers("/activities/{activityId}/boards", "/login", "/", "/join/**", "/reissue", "/swagger-ui/**", "/v3/api-docs/**", "/users/**","/semesters/**").permitAll() + .requestMatchers("/activities/{activityId}/boards","/activities/{activityId}/boards/{boardId}","/login", "/", "/join/**", "/reissue", "/swagger-ui/**", "/v3/api-docs/**", "/users/**","/semesters/**").permitAll() .anyRequest().authenticated()); //JWTFilter 등록 diff --git a/src/main/java/com/haedal/haedalweb/constants/ErrorCode.java b/src/main/java/com/haedal/haedalweb/constants/ErrorCode.java index b7e9b26..9ad4002 100644 --- a/src/main/java/com/haedal/haedalweb/constants/ErrorCode.java +++ b/src/main/java/com/haedal/haedalweb/constants/ErrorCode.java @@ -23,7 +23,8 @@ public enum ErrorCode implements ResponseCode{ NOT_FOUND_SEMESTER_ID(HttpStatus.NOT_FOUND, "014", "해당 학기를 찾을 수 없습니다."), NOT_FOUND_ACTIVITY_ID(HttpStatus.NOT_FOUND, "015", "해당 활동을 찾을 수 없습니다."), EXIST_ACTIVITY(HttpStatus.CONFLICT, "016", "해당 학기에 활동이 존재하는 경우 삭제할 수 없습니다."), - EXIST_BOARD(HttpStatus.CONFLICT, "017", "해당 활동에 게시판이 존재하는 경우 삭제할 수 없습니다."); + EXIST_BOARD(HttpStatus.CONFLICT, "017", "해당 활동에 게시판이 존재하는 경우 삭제할 수 없습니다."), + NOT_FOUND_BOARD_ID(HttpStatus.NOT_FOUND, "018", "해당 게시판을 찾을 수 없습니다."); private final HttpStatus httpStatus; private final String code; diff --git a/src/main/java/com/haedal/haedalweb/controller/BoardController.java b/src/main/java/com/haedal/haedalweb/controller/BoardController.java index d472e14..069805c 100644 --- a/src/main/java/com/haedal/haedalweb/controller/BoardController.java +++ b/src/main/java/com/haedal/haedalweb/controller/BoardController.java @@ -70,4 +70,16 @@ public ResponseEntity> getBoards(@PathVariable Long activityId, return ResponseEntity.ok(boardDTOs); } + + @Operation(summary = "게시판 단일 조회") + @Parameters({ + @Parameter(name = "activityId", description = "게시판 조회할 활동 ID"), + @Parameter(name = "boardId", description = "해당 게시판 ID") + }) + @GetMapping("/activities/{activityId}/boards/{boardId}") + public ResponseEntity getBoard(@PathVariable Long activityId, @PathVariable Long boardId) { + BoardDTO boardDTO = boardService.getBoardDTO(activityId, boardId); + + return ResponseEntity.ok(boardDTO); + } } diff --git a/src/main/java/com/haedal/haedalweb/dto/response/BoardDTO.java b/src/main/java/com/haedal/haedalweb/dto/response/BoardDTO.java index ca3894d..b377c00 100644 --- a/src/main/java/com/haedal/haedalweb/dto/response/BoardDTO.java +++ b/src/main/java/com/haedal/haedalweb/dto/response/BoardDTO.java @@ -13,6 +13,8 @@ @Builder @NoArgsConstructor(access = AccessLevel.PROTECTED) public class BoardDTO { + private Long activityId; + private Long boardId; private String boardName; diff --git a/src/main/java/com/haedal/haedalweb/repository/BoardRepository.java b/src/main/java/com/haedal/haedalweb/repository/BoardRepository.java index b4e0b44..3196ac6 100644 --- a/src/main/java/com/haedal/haedalweb/repository/BoardRepository.java +++ b/src/main/java/com/haedal/haedalweb/repository/BoardRepository.java @@ -6,10 +6,14 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.Optional; + @Repository public interface BoardRepository extends JpaRepository { boolean existsByActivityId(Long activityId); //@Query("select distinct b from Board b join fetch b.participants p join fetch p.user where b.activity.id = :activityId") Page findBoardsByActivityId(Long activityId, Pageable pageable); + + Optional findByActivityIdAndId(Long activityId, Long boardId); } diff --git a/src/main/java/com/haedal/haedalweb/service/BoardService.java b/src/main/java/com/haedal/haedalweb/service/BoardService.java index d4162d6..3949c16 100644 --- a/src/main/java/com/haedal/haedalweb/service/BoardService.java +++ b/src/main/java/com/haedal/haedalweb/service/BoardService.java @@ -58,7 +58,15 @@ public void createBoard(Long activityId, CreateBoardDTO createBoardDTO) { public Page getBoardDTOs(Long activityId, Pageable pageable) { Page boardPage = boardRepository.findBoardsByActivityId(activityId, pageable); - return boardPage.map(this::convertToBoardDTO); + return boardPage.map(board -> convertToBoardDTO(board, activityId)); + } + + @Transactional(readOnly = true) + public BoardDTO getBoardDTO(Long activityId, Long boardId) { + Board board = boardRepository.findByActivityIdAndId(activityId, boardId) + .orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND_BOARD_ID)); + + return convertToBoardDTO(board, activityId); } private void addParticipantsToBoard(Board board, List participants) { @@ -84,8 +92,9 @@ private void validateParticipants(List users, List userIds) { }); } - private BoardDTO convertToBoardDTO(Board board) { + private BoardDTO convertToBoardDTO(Board board, Long activityId) { return BoardDTO.builder() + .activityId(activityId) .boardId(board.getId()) .boardName(board.getName()) .boardIntro(board.getIntro())