From 3a895ce0d4dbf55f03c17e6d06c7cbd2f1dd80d3 Mon Sep 17 00:00:00 2001 From: tfer2442 Date: Sat, 10 Aug 2024 20:57:24 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20Service=20=EC=9D=98=EC=A1=B4=20?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=93=A4?= =?UTF-8?q?=EC=9D=84=20Repository=EB=A5=BC=20=EC=9D=98=EC=A1=B4=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD=20(#69)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../haedalweb/service/ActivityService.java | 4 --- .../haedalweb/service/BoardService.java | 25 ++++++++----------- .../haedal/haedalweb/service/PostService.java | 4 --- .../service/admin/AdminActivityService.java | 6 ++--- .../service/admin/AdminSemesterService.java | 7 +++--- 5 files changed, 15 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/haedal/haedalweb/service/ActivityService.java b/src/main/java/com/haedal/haedalweb/service/ActivityService.java index 7bfb49a..da1106b 100644 --- a/src/main/java/com/haedal/haedalweb/service/ActivityService.java +++ b/src/main/java/com/haedal/haedalweb/service/ActivityService.java @@ -36,8 +36,4 @@ public Activity findActivityById(Long activityId) { return activityRepository.findById(activityId) .orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND_ACTIVITY_ID)); } - - public boolean isSemesterPresent(Long semesterId) { - return activityRepository.existsBySemesterId(semesterId); - } } diff --git a/src/main/java/com/haedal/haedalweb/service/BoardService.java b/src/main/java/com/haedal/haedalweb/service/BoardService.java index f78be5d..fd81aa5 100644 --- a/src/main/java/com/haedal/haedalweb/service/BoardService.java +++ b/src/main/java/com/haedal/haedalweb/service/BoardService.java @@ -12,7 +12,9 @@ import com.haedal.haedalweb.dto.response.BoardDTO; import com.haedal.haedalweb.dto.response.ParticipantDTO; import com.haedal.haedalweb.exception.BusinessException; +import com.haedal.haedalweb.repository.ActivityRepository; import com.haedal.haedalweb.repository.BoardRepository; +import com.haedal.haedalweb.repository.PostRepository; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -25,24 +27,16 @@ @RequiredArgsConstructor @Service public class BoardService { - private final BoardRepository boardRepository; - private final ActivityService activityService; - private final PostService postService; private final UserService userService; + private final BoardRepository boardRepository; + private final ActivityRepository activityRepository; + private final PostRepository postRepository; private final S3Service s3Service; - public boolean isActivityPresent(Long activityId) { - return boardRepository.existsByActivityId(activityId); - } - - public Board findBoardById(Long boardId) { - return boardRepository.findById(boardId) - .orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND_BOARD_ID)); - } - @Transactional public void createBoard(Long activityId, CreateBoardDTO createBoardDTO) { - Activity activity = activityService.findActivityById(activityId); + Activity activity = activityRepository.findById(activityId) + .orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND_ACTIVITY_ID)); User creator = userService.getLoggedInUser(); List participantIds = new ArrayList<>(createBoardDTO.getParticipants()); List participants = userService.findUserByIds(participantIds); @@ -64,7 +58,8 @@ public void createBoard(Long activityId, CreateBoardDTO createBoardDTO) { @Transactional(readOnly = true) public Page getBoardDTOs(Long activityId, Pageable pageable) { - Activity activity = activityService.findActivityById(activityId); + Activity activity = activityRepository.findById(activityId) + .orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND_ACTIVITY_ID)); Page boardPage = boardRepository.findBoardsByActivity(activity, pageable); return boardPage.map(board -> convertToBoardDTO(board, activityId)); @@ -186,7 +181,7 @@ private void validateAuthorityOfBoardManagement(User loggedInUser, User creator) } private void validateDeleteBoardRequest(Long boardId) { - if (postService.isBoardPresent(boardId)) { + if (postRepository.existsByBoardId(boardId)) { throw new BusinessException(ErrorCode.EXIST_POST); } } diff --git a/src/main/java/com/haedal/haedalweb/service/PostService.java b/src/main/java/com/haedal/haedalweb/service/PostService.java index 39edcf0..78eb262 100644 --- a/src/main/java/com/haedal/haedalweb/service/PostService.java +++ b/src/main/java/com/haedal/haedalweb/service/PostService.java @@ -23,10 +23,6 @@ public class PostService { private final BoardRepository boardRepository; private final UserService userService; - public boolean isBoardPresent(Long boardId) { - return postRepository.existsByBoardId(boardId); - } - @Transactional public void createPost(Long boardId, CreatePostDTO createPostDTO) { // createPost 리팩토링 해야함. // Board board = boardService.findBoardById(boardId); diff --git a/src/main/java/com/haedal/haedalweb/service/admin/AdminActivityService.java b/src/main/java/com/haedal/haedalweb/service/admin/AdminActivityService.java index 51e666e..45d0b37 100644 --- a/src/main/java/com/haedal/haedalweb/service/admin/AdminActivityService.java +++ b/src/main/java/com/haedal/haedalweb/service/admin/AdminActivityService.java @@ -2,14 +2,12 @@ import com.haedal.haedalweb.constants.ErrorCode; import com.haedal.haedalweb.domain.Activity; -import com.haedal.haedalweb.domain.Board; import com.haedal.haedalweb.domain.Semester; import com.haedal.haedalweb.dto.request.CreateActivityDTO; import com.haedal.haedalweb.exception.BusinessException; import com.haedal.haedalweb.repository.ActivityRepository; import com.haedal.haedalweb.repository.BoardRepository; import com.haedal.haedalweb.repository.SemesterRepository; -import com.haedal.haedalweb.service.BoardService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -19,7 +17,7 @@ public class AdminActivityService { private final SemesterRepository semesterRepository; private final ActivityRepository activityRepository; - private final BoardService boardService; + private final BoardRepository boardRepository; @Transactional public void createActivity(Long semesterId, CreateActivityDTO createActivityDTO) { @@ -44,7 +42,7 @@ public void deleteActivity(Long activityId) { } private void validateDeleteActivityRequest(Long activityId) { - if (boardService.isActivityPresent(activityId)) { + if (boardRepository.existsByActivityId(activityId)) { throw new BusinessException(ErrorCode.EXIST_BOARD); } } diff --git a/src/main/java/com/haedal/haedalweb/service/admin/AdminSemesterService.java b/src/main/java/com/haedal/haedalweb/service/admin/AdminSemesterService.java index 5d4c2d2..7f44e1e 100644 --- a/src/main/java/com/haedal/haedalweb/service/admin/AdminSemesterService.java +++ b/src/main/java/com/haedal/haedalweb/service/admin/AdminSemesterService.java @@ -4,8 +4,8 @@ import com.haedal.haedalweb.domain.Semester; import com.haedal.haedalweb.dto.request.CreateSemesterDTO; import com.haedal.haedalweb.exception.BusinessException; +import com.haedal.haedalweb.repository.ActivityRepository; import com.haedal.haedalweb.repository.SemesterRepository; -import com.haedal.haedalweb.service.ActivityService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -14,7 +14,7 @@ @RequiredArgsConstructor public class AdminSemesterService { private final SemesterRepository semesterRepository; - private final ActivityService activityService; + private final ActivityRepository activityRepository; @Transactional public void createSemester(CreateSemesterDTO createSemesterDTO) { @@ -35,7 +35,6 @@ public void deleteSemester(Long semesterId) { validateDeleteSemesterRequest(semesterId); - // 학기 안에 활동이 존재할 때, 에러 코드 반환하는 로직 작성 semesterRepository.delete(semester); } @@ -46,7 +45,7 @@ private void validateAddSemesterRequest(CreateSemesterDTO createSemesterDTO) { } private void validateDeleteSemesterRequest(Long semesterId) { - if (activityService.isSemesterPresent(semesterId)) { + if (activityRepository.existsBySemesterId(semesterId)) { throw new BusinessException(ErrorCode.EXIST_ACTIVITY); } } From 9f2bd59cd3418a597e47b5fd269c5391ee20dd1d Mon Sep 17 00:00:00 2001 From: tfer2442 Date: Sat, 10 Aug 2024 22:17:39 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=EA=B2=8C=C3=AC=C2=8B=ED=99=9C?= =?UTF-8?q?=C3=A3=C2=84=EB=8F=99=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20api=20(#69)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../haedalweb/config/SecurityConfig.java | 1 + .../haedal/haedalweb/constants/ErrorCode.java | 2 +- .../haedalweb/controller/PostController.java | 2 +- .../com/haedal/haedalweb/domain/Post.java | 2 +- .../haedal/haedalweb/service/PostService.java | 29 ++++++++++++++----- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/haedal/haedalweb/config/SecurityConfig.java b/src/main/java/com/haedal/haedalweb/config/SecurityConfig.java index 023120c..a73bfd6 100644 --- a/src/main/java/com/haedal/haedalweb/config/SecurityConfig.java +++ b/src/main/java/com/haedal/haedalweb/config/SecurityConfig.java @@ -80,6 +80,7 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { .requestMatchers(HttpMethod.POST, "/notice/posts", "/event/posts").hasAnyRole("WEB_MASTER", "ADMIN") .requestMatchers(HttpMethod.POST, "/activities/{activityId}/boards").hasAnyRole("WEB_MASTER", "ADMIN", "TEAM_LEADER") .requestMatchers(HttpMethod.POST, "/boards/{boardId}/posts").authenticated() + .requestMatchers(HttpMethod.DELETE, "/boards/{boardId}/posts/{postId}").authenticated() .requestMatchers(HttpMethod.DELETE, "/activities/{activityId}/boards/{boardId}").hasAnyRole("WEB_MASTER", "ADMIN", "TEAM_LEADER") .requestMatchers(HttpMethod.PATCH, "/activities/{activityId}/boards/{boardId}/**").hasAnyRole("WEB_MASTER", "ADMIN", "TEAM_LEADER") .requestMatchers("/private/users").authenticated() diff --git a/src/main/java/com/haedal/haedalweb/constants/ErrorCode.java b/src/main/java/com/haedal/haedalweb/constants/ErrorCode.java index c5588e3..aba8d81 100644 --- a/src/main/java/com/haedal/haedalweb/constants/ErrorCode.java +++ b/src/main/java/com/haedal/haedalweb/constants/ErrorCode.java @@ -25,7 +25,7 @@ public enum ErrorCode implements ResponseCode{ EXIST_ACTIVITY(HttpStatus.CONFLICT, "016", "해당 학기에 활동이 존재하는 경우 삭제할 수 없습니다."), EXIST_BOARD(HttpStatus.CONFLICT, "017", "해당 활동에 게시판이 존재하는 경우 삭제할 수 없습니다."), NOT_FOUND_BOARD_ID(HttpStatus.NOT_FOUND, "018", "해당 게시판을 찾을 수 없습니다."), - FORBIDDEN_UPDATE(HttpStatus.FORBIDDEN, "019", "삭제 권한이 없습니다."), + FORBIDDEN_UPDATE(HttpStatus.FORBIDDEN, "019", "수정, 삭제 권한이 없습니다."), NOT_FOUND_POST_TYPE(HttpStatus.NOT_FOUND, "020", "해당 게시글 타입이 존재하지 않습니다."), EXIST_POST(HttpStatus.CONFLICT, "021", "해당 게시판에 게시글이 존재하는 경우 삭제할 수 없습니다."), NOT_FOUND_POST_ID(HttpStatus.NOT_FOUND, "022", "해당 게시글을 찾을 수 없습니다."); diff --git a/src/main/java/com/haedal/haedalweb/controller/PostController.java b/src/main/java/com/haedal/haedalweb/controller/PostController.java index a954e60..06d84c4 100644 --- a/src/main/java/com/haedal/haedalweb/controller/PostController.java +++ b/src/main/java/com/haedal/haedalweb/controller/PostController.java @@ -72,7 +72,7 @@ public ResponseEntity addEventPost(@RequestBody @Valid CreatePo @Operation(summary = "활동 게시글 삭제") @ApiSuccessCodeExample(SuccessCode.DELETE_POST_SUCCESS) - @ApiErrorCodeExamples({}) + @ApiErrorCodeExamples({ErrorCode.NOT_FOUND_POST_ID, ErrorCode.NOT_FOUND_BOARD_ID, ErrorCode.FORBIDDEN_UPDATE}) @Parameters({ @Parameter(name = "boardId", description = "게시글 삭제할 활동 게시판 ID"), @Parameter(name = "postId", description = "해당 게시글 ID") diff --git a/src/main/java/com/haedal/haedalweb/domain/Post.java b/src/main/java/com/haedal/haedalweb/domain/Post.java index c1efbd8..b87d52b 100644 --- a/src/main/java/com/haedal/haedalweb/domain/Post.java +++ b/src/main/java/com/haedal/haedalweb/domain/Post.java @@ -66,7 +66,7 @@ public class Post { @JoinColumn(name = "user_id") private User user; - @OneToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "board_id") private Board board; } diff --git a/src/main/java/com/haedal/haedalweb/service/PostService.java b/src/main/java/com/haedal/haedalweb/service/PostService.java index 78eb262..472c6dd 100644 --- a/src/main/java/com/haedal/haedalweb/service/PostService.java +++ b/src/main/java/com/haedal/haedalweb/service/PostService.java @@ -4,6 +4,7 @@ import com.haedal.haedalweb.domain.Board; import com.haedal.haedalweb.domain.Post; import com.haedal.haedalweb.domain.PostType; +import com.haedal.haedalweb.domain.Role; import com.haedal.haedalweb.domain.User; import com.haedal.haedalweb.dto.request.CreatePostDTO; import com.haedal.haedalweb.exception.BusinessException; @@ -22,10 +23,10 @@ public class PostService { private final PostRepository postRepository; private final BoardRepository boardRepository; private final UserService userService; + private final S3Service s3Service; @Transactional - public void createPost(Long boardId, CreatePostDTO createPostDTO) { // createPost 리팩토링 해야함. - // Board board = boardService.findBoardById(boardId); + public void createPost(Long boardId, CreatePostDTO createPostDTO) { // createPost 리팩토링 해야함. // 게시판 참여자만 게시글을 쓸 수 있게 해야하나? Board board = boardRepository.findById(boardId) .orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND_BOARD_ID)); PostType postType; @@ -50,7 +51,7 @@ public void createPost(Long boardId, CreatePostDTO createPostDTO) { // createPos .activityDate(activityDate) .createDate(createDate) .user(creator) - .board(board) // 만약 boardId를 안 받았으면, 공지사항 or 이베트 게시글임 + .board(board) .build(); postRepository.save(post); @@ -90,15 +91,29 @@ public void createPost(CreatePostDTO createPostDTO) { public void deletePost(Long boardId, Long postId) { // 활동 게시글 삭제 method Post post = postRepository.findByBoardIdAndId(boardId, postId) .orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND_POST_ID)); - //Board board = boardService.findBoardById(boardId); + Board board = boardRepository.findById(boardId) + .orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND_BOARD_ID)); User loggedInUser = userService.getLoggedInUser(); User postCreator = post.getUser(); - // User boardCreator = board.getUser(); + User boardCreator = board.getUser(); - //validateAuthorityOfPostManagement + validateAuthorityOfPostManagement(loggedInUser, postCreator, boardCreator); - // 게시판 생성한 것은 팀장이므로, 게시판 생성자와 WEB_MASTER, 해구르르, 게시글 작성자만 삭제 가능 + s3Service.deleteObject(post.getImageUrl()); + postRepository.delete(post); + } + private void validateAuthorityOfPostManagement(User loggedInUser, User postCreator, User boardCreator) { + String loggedInUserId = loggedInUser.getId(); + String postCreatorId = postCreator.getId(); + String boardCreatorId = boardCreator.getId(); + + if (!postCreatorId.equals(loggedInUserId) + && !boardCreatorId.equals(loggedInUserId) + && loggedInUser.getRole() != Role.ROLE_ADMIN + && loggedInUser.getRole() != Role.ROLE_WEB_MASTER) { + throw new BusinessException(ErrorCode.FORBIDDEN_UPDATE); + } } } From b49c2c878baf92b4df559a24ec65808430caff44 Mon Sep 17 00:00:00 2001 From: tfer2442 Date: Sat, 10 Aug 2024 22:26:11 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=EA=B3=B5=EC=A7=80=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?api=20(#69)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../haedal/haedalweb/config/SecurityConfig.java | 1 + .../haedalweb/controller/PostController.java | 14 ++++++++++++++ .../haedal/haedalweb/service/PostService.java | 16 ++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/main/java/com/haedal/haedalweb/config/SecurityConfig.java b/src/main/java/com/haedal/haedalweb/config/SecurityConfig.java index a73bfd6..4c16403 100644 --- a/src/main/java/com/haedal/haedalweb/config/SecurityConfig.java +++ b/src/main/java/com/haedal/haedalweb/config/SecurityConfig.java @@ -78,6 +78,7 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { .requestMatchers("/boards/generate-presigned-url").hasAnyRole("WEB_MASTER", "ADMIN", "TEAM_LEADER") .requestMatchers(HttpMethod.GET, "/posts/generate-presigned-url").hasAnyRole("WEB_MASTER", "ADMIN", "TEAM_LEADER", "MEMBER") .requestMatchers(HttpMethod.POST, "/notice/posts", "/event/posts").hasAnyRole("WEB_MASTER", "ADMIN") + .requestMatchers(HttpMethod.DELETE, "/notice/posts/{postId}, /event/posts/{postId}").hasAnyRole("WEB_MASTER", "ADMIN") .requestMatchers(HttpMethod.POST, "/activities/{activityId}/boards").hasAnyRole("WEB_MASTER", "ADMIN", "TEAM_LEADER") .requestMatchers(HttpMethod.POST, "/boards/{boardId}/posts").authenticated() .requestMatchers(HttpMethod.DELETE, "/boards/{boardId}/posts/{postId}").authenticated() diff --git a/src/main/java/com/haedal/haedalweb/controller/PostController.java b/src/main/java/com/haedal/haedalweb/controller/PostController.java index 06d84c4..1947cad 100644 --- a/src/main/java/com/haedal/haedalweb/controller/PostController.java +++ b/src/main/java/com/haedal/haedalweb/controller/PostController.java @@ -83,4 +83,18 @@ public ResponseEntity deletePost(@PathVariable Long boardId, @P return ResponseUtil.buildSuccessResponseEntity(SuccessCode.DELETE_POST_SUCCESS); } + + @Operation(summary = "공지사항 게시글 삭제") + @ApiSuccessCodeExample(SuccessCode.DELETE_POST_SUCCESS) + @ApiErrorCodeExamples({ErrorCode.NOT_FOUND_POST_ID, ErrorCode.NOT_FOUND_POST_TYPE}) + @Parameters({ + @Parameter(name = "postId", description = "해당 게시글 ID") + }) + @DeleteMapping("/notice/posts/{postId}") + public ResponseEntity deleteNoticePost(@PathVariable Long postId) { + postService.deletePost(postId); + + return ResponseUtil.buildSuccessResponseEntity(SuccessCode.DELETE_POST_SUCCESS); + } + } diff --git a/src/main/java/com/haedal/haedalweb/service/PostService.java b/src/main/java/com/haedal/haedalweb/service/PostService.java index 472c6dd..4455c8c 100644 --- a/src/main/java/com/haedal/haedalweb/service/PostService.java +++ b/src/main/java/com/haedal/haedalweb/service/PostService.java @@ -104,6 +104,22 @@ public void deletePost(Long boardId, Long postId) { // 활동 게시글 삭제 m postRepository.delete(post); } + @Transactional + public void deletePost(Long postId) { + Post post = postRepository.findById(postId) + .orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND_POST_ID)); + + try { + if (post.getPostType() != PostType.NOTICE && post.getPostType() != PostType.EVENT) + throw new IllegalArgumentException(); + } catch (IllegalArgumentException e) { + throw new BusinessException(ErrorCode.NOT_FOUND_POST_TYPE); + } + + s3Service.deleteObject(post.getImageUrl()); + postRepository.delete(post); + } + private void validateAuthorityOfPostManagement(User loggedInUser, User postCreator, User boardCreator) { String loggedInUserId = loggedInUser.getId(); String postCreatorId = postCreator.getId(); From e6f630c0a4835dc5a5b300cb932af64907cb69f6 Mon Sep 17 00:00:00 2001 From: tfer2442 Date: Sat, 10 Aug 2024 22:37:06 +0900 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20=EA=B3=B5=EC=A7=80=EC=82=AC?= =?UTF-8?q?=ED=95=AD,=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EA=B8=80=20=EC=82=AD=EC=A0=9C=20API=20(#69)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../haedalweb/config/SecurityConfig.java | 4 ++-- .../haedalweb/controller/PostController.java | 18 ++++-------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/haedal/haedalweb/config/SecurityConfig.java b/src/main/java/com/haedal/haedalweb/config/SecurityConfig.java index 4c16403..dd7933f 100644 --- a/src/main/java/com/haedal/haedalweb/config/SecurityConfig.java +++ b/src/main/java/com/haedal/haedalweb/config/SecurityConfig.java @@ -77,8 +77,8 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { .requestMatchers("/admin/**").hasAnyRole("WEB_MASTER", "ADMIN") .requestMatchers("/boards/generate-presigned-url").hasAnyRole("WEB_MASTER", "ADMIN", "TEAM_LEADER") .requestMatchers(HttpMethod.GET, "/posts/generate-presigned-url").hasAnyRole("WEB_MASTER", "ADMIN", "TEAM_LEADER", "MEMBER") - .requestMatchers(HttpMethod.POST, "/notice/posts", "/event/posts").hasAnyRole("WEB_MASTER", "ADMIN") - .requestMatchers(HttpMethod.DELETE, "/notice/posts/{postId}, /event/posts/{postId}").hasAnyRole("WEB_MASTER", "ADMIN") + .requestMatchers(HttpMethod.POST, "/posts").hasAnyRole("WEB_MASTER", "ADMIN") + .requestMatchers(HttpMethod.DELETE, "/posts/{postId}").hasAnyRole("WEB_MASTER", "ADMIN") .requestMatchers(HttpMethod.POST, "/activities/{activityId}/boards").hasAnyRole("WEB_MASTER", "ADMIN", "TEAM_LEADER") .requestMatchers(HttpMethod.POST, "/boards/{boardId}/posts").authenticated() .requestMatchers(HttpMethod.DELETE, "/boards/{boardId}/posts/{postId}").authenticated() diff --git a/src/main/java/com/haedal/haedalweb/controller/PostController.java b/src/main/java/com/haedal/haedalweb/controller/PostController.java index 1947cad..b93bfc7 100644 --- a/src/main/java/com/haedal/haedalweb/controller/PostController.java +++ b/src/main/java/com/haedal/haedalweb/controller/PostController.java @@ -7,7 +7,6 @@ import com.haedal.haedalweb.dto.response.common.SuccessResponse; import com.haedal.haedalweb.service.PostService; import com.haedal.haedalweb.service.S3Service; -import com.haedal.haedalweb.swagger.ApiErrorCodeExample; import com.haedal.haedalweb.swagger.ApiErrorCodeExamples; import com.haedal.haedalweb.swagger.ApiSuccessCodeExample; import com.haedal.haedalweb.util.ResponseUtil; @@ -52,21 +51,13 @@ public ResponseEntity addPost(@PathVariable Long boardId, @Requ return ResponseUtil.buildSuccessResponseEntity(SuccessCode.ADD_POST_SUCCESS); } - @Operation(summary = "공지사항 게시글 생성") + @Operation(summary = "공지사항, 이벤트 게시글 생성") @ApiSuccessCodeExample(SuccessCode.ADD_POST_SUCCESS) @ApiErrorCodeExamples({ErrorCode.NOT_FOUND_USER_ID, ErrorCode.NOT_FOUND_BOARD_ID, ErrorCode.NOT_FOUND_POST_TYPE}) - @PostMapping("/notice/posts") + @PostMapping("/posts") public ResponseEntity addNoticePost(@RequestBody @Valid CreatePostDTO createPostDTO) { postService.createPost(createPostDTO); - return ResponseUtil.buildSuccessResponseEntity(SuccessCode.ADD_POST_SUCCESS); - } - @Operation(summary = "이벤트 게시글 생성") - @ApiSuccessCodeExample(SuccessCode.ADD_POST_SUCCESS) - @ApiErrorCodeExamples({ErrorCode.NOT_FOUND_USER_ID, ErrorCode.NOT_FOUND_BOARD_ID, ErrorCode.NOT_FOUND_POST_TYPE}) - @PostMapping("/event/posts") - public ResponseEntity addEventPost(@RequestBody @Valid CreatePostDTO createPostDTO) { - postService.createPost(createPostDTO); return ResponseUtil.buildSuccessResponseEntity(SuccessCode.ADD_POST_SUCCESS); } @@ -84,17 +75,16 @@ public ResponseEntity deletePost(@PathVariable Long boardId, @P return ResponseUtil.buildSuccessResponseEntity(SuccessCode.DELETE_POST_SUCCESS); } - @Operation(summary = "공지사항 게시글 삭제") + @Operation(summary = "공지사항, 이벤트 게시글 삭제") @ApiSuccessCodeExample(SuccessCode.DELETE_POST_SUCCESS) @ApiErrorCodeExamples({ErrorCode.NOT_FOUND_POST_ID, ErrorCode.NOT_FOUND_POST_TYPE}) @Parameters({ @Parameter(name = "postId", description = "해당 게시글 ID") }) - @DeleteMapping("/notice/posts/{postId}") + @DeleteMapping("/posts/{postId}") public ResponseEntity deleteNoticePost(@PathVariable Long postId) { postService.deletePost(postId); return ResponseUtil.buildSuccessResponseEntity(SuccessCode.DELETE_POST_SUCCESS); } - }