-
Notifications
You must be signed in to change notification settings - Fork 2
20260221 #229 게시판 관리 기능 이관 #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
The head ref may contain hidden characters: "20260221-#229-\uAC8C\uC2DC\uD310-\uAD00\uB9AC-\uAE30\uB2A5-\uC774\uAD00"
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
backend/src/main/java/org/sejongisc/backend/admin/controller/AdminBoardController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,62 @@ | ||
| package org.sejongisc.backend.admin.controller; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import java.util.UUID; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.sejongisc.backend.board.dto.BoardRequest; | ||
| import org.sejongisc.backend.admin.service.AdminBoardService; | ||
| import org.sejongisc.backend.common.auth.dto.CustomUserDetails; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/board/admin") | ||
| @Tag( | ||
| name = "게시판 관리 API", | ||
| description = "게시판 생성 및 삭제 관련 API 제공" | ||
| ) | ||
| public class AdminBoardController { | ||
|
|
||
| private final AdminBoardService adminBoardService; | ||
|
|
||
| // 게시판 생성 | ||
| @Operation( | ||
| summary = "게시판 생성", | ||
| description = "게시판 이름과 상위 게시판 ID를 포함한 새로운 게시판을 생성합니다." | ||
| + "상위 게시판의 ID가 null 이면 최상위 게시판으로 생성됩니다." | ||
| + "회장만 생성할 수 있습니다." | ||
| ) | ||
| @PostMapping | ||
| public ResponseEntity<Void> createBoard( | ||
| @RequestBody @Valid BoardRequest request, | ||
| @AuthenticationPrincipal CustomUserDetails customUserDetails) { | ||
| UUID userId = customUserDetails.getUserId(); | ||
| adminBoardService.createBoard(request, userId); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
|
|
||
| // 게시판 삭제 | ||
| @Operation( | ||
| summary = "게시판 삭제", | ||
| description = "게시판 ID를 통해 게시판을 삭제합니다." | ||
| + "회장만 삭제할 수 있습니다." | ||
| + "관련 첨부파일 및 댓글 등도 함께 삭제됩니다." | ||
| ) | ||
| @DeleteMapping("/{boardId}") | ||
| public ResponseEntity<?> deleteBoard( | ||
| @PathVariable UUID boardId, | ||
| @AuthenticationPrincipal CustomUserDetails customUserDetails) { | ||
| UUID userId = customUserDetails.getUserId(); | ||
| adminBoardService.deleteBoard(boardId, userId); | ||
| return ResponseEntity.ok("게시판 삭제가 완료되었습니다."); | ||
| } | ||
| } | ||
91 changes: 91 additions & 0 deletions
91
backend/src/main/java/org/sejongisc/backend/admin/service/AdminBoardService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package org.sejongisc.backend.admin.service; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import java.util.stream.Stream; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.sejongisc.backend.board.dto.BoardRequest; | ||
| import org.sejongisc.backend.board.entity.Board; | ||
| import org.sejongisc.backend.board.repository.BoardRepository; | ||
| import org.sejongisc.backend.board.repository.PostRepository; | ||
| import org.sejongisc.backend.board.service.PostService; | ||
| import org.sejongisc.backend.common.exception.CustomException; | ||
| import org.sejongisc.backend.common.exception.ErrorCode; | ||
| import org.sejongisc.backend.user.entity.Role; | ||
| import org.sejongisc.backend.user.entity.User; | ||
| import org.sejongisc.backend.user.repository.UserRepository; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Slf4j | ||
| public class AdminBoardService { | ||
|
|
||
| private final UserRepository userRepository; | ||
| private final PostRepository postRepository; | ||
| private final BoardRepository boardRepository; | ||
| private final PostService postService; | ||
|
|
||
| // 게시판 생성 | ||
| @Transactional | ||
| public void createBoard(BoardRequest request, UUID userId) { | ||
| User user = userRepository.findById(userId) | ||
| .orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND)); | ||
|
|
||
| // 회장만 게시판 생성 가능 | ||
| if (!user.getRole().equals(Role.PRESIDENT)) { | ||
| throw new CustomException(ErrorCode.BOARD_ACCESS_DENIED); | ||
| } | ||
|
|
||
| Board board; | ||
| // 하위 게시판인 경우 | ||
| if (request.getParentBoardId() != null) { | ||
| Board parentBoard = boardRepository.findById(request.getParentBoardId()) | ||
| .orElseThrow(() -> new CustomException(ErrorCode.BOARD_NOT_FOUND)); | ||
|
|
||
| board = Board.builder() | ||
| .boardName(request.getBoardName()) | ||
| .createdBy(user) | ||
| .parentBoard(parentBoard) | ||
| .build(); | ||
nayoung04 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else { | ||
| // 상위 게시판인 경우 | ||
| board = Board.builder() | ||
| .boardName(request.getBoardName()) | ||
| .createdBy(user) | ||
| .parentBoard(null) | ||
| .build(); | ||
| } | ||
|
|
||
| boardRepository.save(board); | ||
| } | ||
|
|
||
| // 게시판 삭제 | ||
| @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.BOARD_ACCESS_DENIED); | ||
| } | ||
|
|
||
| boardRepository.findById(boardId) | ||
| .orElseThrow(() -> new CustomException(ErrorCode.BOARD_NOT_FOUND)); | ||
|
|
||
| // 상위 게시판이면 하위 게시판 목록을 조회 | ||
| List<UUID> targetBoardIds = Stream.concat( | ||
| Stream.of(boardId), // 자신 포함 | ||
| boardRepository.findAllByParentBoard_BoardId(boardId).stream() | ||
| .map(Board::getBoardId) | ||
| ).toList(); | ||
nayoung04 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // 각 boardId마다 postId/userId 조회해서 삭제 | ||
| targetBoardIds.stream() | ||
| .flatMap(id -> postRepository.findPostIdAndUserIdByBoardId(id).stream()) | ||
| .forEach(row -> postService.deletePost(row.getPostId(), row.getUserId())); | ||
| targetBoardIds.forEach(boardRepository::deleteById); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.