Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,34 @@ public ResponseEntity<List<BoardResponse>> getParentBoards(
return ResponseEntity.ok(postService.getParentBoards());
}


// 게시판 생성
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

주석이 잘못되었습니다.

주석이 "게시판 생성"으로 되어 있으나, 실제로는 "하위 게시판 목록 조회" 기능입니다. 복사-붙여넣기 실수로 보입니다.

-  // 게시판 생성
+  // 하위 게시판 목록 조회
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// 게시판 생성
// 하위 게시판 목록 조회
🤖 Prompt for AI Agents
In
backend/src/main/java/org/sejongisc/backend/board/controller/BoardController.java
around line 164, the inline comment currently reads "게시판 생성" but the method
actually implements "하위 게시판 목록 조회"; update the comment to accurately describe
the method (e.g., "하위 게시판 목록 조회" or the appropriate Javadoc/mapping
description), and scan nearby comments for any other copy-paste mismatches to
correct them as well.

@Operation(
summary = "하위 게시판 목록 조회",
description = "하위 게시판 목록을 조회합니다."
)
@GetMapping("/childs")
public ResponseEntity<List<BoardResponse>> getChildBoards(
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
return ResponseEntity.ok(postService.getChildBoards());
}

// 게시글 삭제
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

주석이 잘못되었습니다.

주석이 "게시글 삭제"로 되어 있으나, 실제로는 "게시판 삭제" 기능입니다.

-  // 게시글 삭제
+  // 게시판 삭제
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// 게시글 삭제
// 게시판 삭제
🤖 Prompt for AI Agents
In
backend/src/main/java/org/sejongisc/backend/board/controller/BoardController.java
around line 175, the inline comment incorrectly reads "게시글 삭제" but the method
implements deletion of a board; update the comment to "게시판 삭제" (or a more
descriptive "게시판 삭제 처리" / "Delete board") to accurately reflect the
functionality and keep any adjacent JavaDoc or method-level comments consistent.

@Operation(
summary = "게시판 삭제",
description = "게시판 ID를 통해 게시판을 삭제합니다."
+ "회장만 삭제할 수 있습니다."
+ "관련 첨부파일 및 댓글 등도 함께 삭제됩니다."
)
@DeleteMapping("/{boardId}")
public ResponseEntity<?> deleteBoard(
@PathVariable UUID boardId,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
UUID userId = customUserDetails.getUserId();
postService.deleteBoard(boardId, userId);
return ResponseEntity.ok("게시판 삭제가 완료되었습니다.");
}

// 좋아요 토글
@Operation(
summary = "좋아요 등록 및 취소",
Expand Down Expand Up @@ -236,4 +264,7 @@ public void deleteComment(
UUID userId = customUserDetails.getUserId();
postInteractionService.deleteComment(commentId, userId);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@
public interface BoardRepository extends JpaRepository<Board, UUID> {

List<Board> findAllByParentBoardIsNull();
List<Board> findAllByParentBoardIsNotNull();
List<Board> findAllByParentBoard_BoardId(UUID parentBoardId);

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.sejongisc.backend.board.repository;

import java.util.List;
import java.util.UUID;
import org.sejongisc.backend.board.entity.Board;
import org.sejongisc.backend.board.entity.Post;
import org.sejongisc.backend.board.repository.projection.PostIdUserIdProjection;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -23,4 +25,11 @@ Page<Post> searchByBoardAndKeyword(
@Param("board") Board board,
@Param("keyword") String keyword,
Pageable pageable);

@Query("""
select p.postId as postId, p.user.userId as userId
from Post p
where p.board.boardId = :boardId
""")
List<PostIdUserIdProjection> findPostIdAndUserIdByBoardId(@Param("boardId") UUID boardId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.sejongisc.backend.board.repository.projection;

import java.util.UUID;

public interface PostIdUserIdProjection {
UUID getPostId();
UUID getUserId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ public interface PostService {

// 부모 게시판 목록 조회
List<BoardResponse> getParentBoards();
// 하위 게시판 목록 조회
List<BoardResponse> getChildBoards();
void deleteBoard(UUID boardId, UUID boardUserId);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.sejongisc.backend.board.service;

import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.sejongisc.backend.board.dto.BoardRequest;
Expand All @@ -20,10 +24,12 @@
import org.sejongisc.backend.board.repository.PostBookmarkRepository;
import org.sejongisc.backend.board.repository.PostLikeRepository;
import org.sejongisc.backend.board.repository.PostRepository;
import org.sejongisc.backend.board.repository.projection.PostIdUserIdProjection;
import org.sejongisc.backend.common.exception.CustomException;
import org.sejongisc.backend.common.exception.ErrorCode;
import org.sejongisc.backend.user.dao.UserRepository;
import org.sejongisc.backend.user.dto.UserInfoResponse;
import org.sejongisc.backend.user.entity.Role;
import org.sejongisc.backend.user.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand Down Expand Up @@ -169,6 +175,28 @@ public void deletePost(UUID postId, UUID userId) {
postRepository.delete(post);
}

@Transactional
public void deleteBoard(UUID boardId, UUID boardUserId) {
User user = userRepository.findById(boardUserId).orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
if(!user.getRole().equals(Role.PRESIDENT)){
throw new CustomException(ErrorCode.INVALID_BOARD_OWNER);
}
//상위 게시판이면 하위 게시판 목록을 조회
// 1. 부모 + 자식 boardId 목록 만들기
List<UUID> targetBoardIds = Stream.concat(
Stream.of(boardId), // 자신 포함
boardRepository.findAllByParentBoard_BoardId(boardId).stream()
.map(Board::getBoardId)
).toList();

// 2. 각 boardId마다 postId/userId 조회해서 삭제
targetBoardIds.stream()
.flatMap(id -> postRepository.findPostIdAndUserIdByBoardId(id).stream())
.forEach(row -> deletePost(row.getPostId(), row.getUserId()));
targetBoardIds.forEach(boardRepository::deleteById);
return;
}
Comment on lines +178 to +198
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

@Override 어노테이션 누락 및 불필요한 return 문.

deleteBoard 메서드에 @Override 어노테이션이 누락되었고, line 197의 return; 문은 불필요합니다.

+  @Override
   @Transactional
   public void deleteBoard(UUID boardId, UUID boardUserId) {
     // ... existing code ...
     targetBoardIds.forEach(boardRepository::deleteById);
-    return;
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Transactional
public void deleteBoard(UUID boardId, UUID boardUserId) {
User user = userRepository.findById(boardUserId).orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
if(!user.getRole().equals(Role.PRESIDENT)){
throw new CustomException(ErrorCode.INVALID_BOARD_OWNER);
}
//상위 게시판이면 하위 게시판 목록을 조회
// 1. 부모 + 자식 boardId 목록 만들기
List<UUID> targetBoardIds = Stream.concat(
Stream.of(boardId), // 자신 포함
boardRepository.findAllByParentBoard_BoardId(boardId).stream()
.map(Board::getBoardId)
).toList();
// 2. 각 boardId마다 postId/userId 조회해서 삭제
targetBoardIds.stream()
.flatMap(id -> postRepository.findPostIdAndUserIdByBoardId(id).stream())
.forEach(row -> deletePost(row.getPostId(), row.getUserId()));
targetBoardIds.forEach(boardRepository::deleteById);
return;
}
@Override
@Transactional
public void deleteBoard(UUID boardId, UUID boardUserId) {
User user = userRepository.findById(boardUserId).orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
if(!user.getRole().equals(Role.PRESIDENT)){
throw new CustomException(ErrorCode.INVALID_BOARD_OWNER);
}
//상위 게시판이면 하위 게시판 목록을 조회
// 1. 부모 + 자식 boardId 목록 만들기
List<UUID> targetBoardIds = Stream.concat(
Stream.of(boardId), // 자신 포함
boardRepository.findAllByParentBoard_BoardId(boardId).stream()
.map(Board::getBoardId)
).toList();
// 2. 각 boardId마다 postId/userId 조회해서 삭제
targetBoardIds.stream()
.flatMap(id -> postRepository.findPostIdAndUserIdByBoardId(id).stream())
.forEach(row -> deletePost(row.getPostId(), row.getUserId()));
targetBoardIds.forEach(boardRepository::deleteById);
}
🤖 Prompt for AI Agents
In
backend/src/main/java/org/sejongisc/backend/board/service/PostServiceImpl.java
around lines 178 to 198, the deleteBoard method is missing the @Override
annotation and contains an unnecessary trailing "return;" at line 197; add the
@Override annotation immediately above the method signature and remove the
redundant "return;" statement so the method ends naturally after deleting boards
and posts.


// 게시물 조회 (해당 게시판의 게시물)
@Override
@Transactional(readOnly = true)
Expand Down Expand Up @@ -307,6 +335,16 @@ public List<BoardResponse> getParentBoards() {
.toList();
}

// 하위 게시판 조회
@Transactional(readOnly = true)
public List<BoardResponse> getChildBoards() {
List<Board> childBoards = boardRepository.findAllByParentBoardIsNotNull();

return childBoards.stream()
.map(BoardResponse::from)
.toList();
}
Comment on lines +338 to +346
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

@Override 어노테이션 누락.

getChildBoards 메서드가 PostService 인터페이스를 구현하고 있다면 @Override 어노테이션이 필요합니다.

   // 하위 게시판 조회
+  @Override
   @Transactional(readOnly = true)
   public List<BoardResponse> getChildBoards() {
🤖 Prompt for AI Agents
In
backend/src/main/java/org/sejongisc/backend/board/service/PostServiceImpl.java
around lines 338 to 346, the getChildBoards() method is missing the @Override
annotation; if this method implements PostService, add the @Override annotation
immediately above the method signature to reflect interface implementation and
help the compiler catch signature mismatches.


private PostResponse mapToPostResponse(Post post) {
return PostResponse.builder()
.postId(post.getPostId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public enum ErrorCode {

POST_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 게시물을 찾을 수 없습니다."),

INVALID_BOARD_OWNER(HttpStatus.FORBIDDEN, "게시판 수정/삭제 권한이 없습니다."),

INVALID_POST_OWNER(HttpStatus.FORBIDDEN, "게시물 수정/삭제 권한이 없습니다."),

COMMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 댓글을 찾을 수 없습니다."),
Expand All @@ -101,6 +103,9 @@ public enum ErrorCode {

INVALID_BOARD_TYPE(HttpStatus.BAD_REQUEST, "상위 게시판에는 글을 작성할 수 없습니다.");




private final HttpStatus status;
private final String message;

Expand Down