From 34ca10be00eecd84dfb3d5e25081f5d10978351f Mon Sep 17 00:00:00 2001 From: strongmhk Date: Thu, 22 Aug 2024 10:42:57 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20[#148]=20feature:=20=EC=BB=A4?= =?UTF-8?q?=EB=B0=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/CommunityPostCommandService.java | 1 + .../CommunityPostCommandServiceImpl.java | 16 +++++++++++++- .../CommunityPostRestController.java | 16 +++++++++++--- .../post/web/dto/CommunityPostRequestDTO.java | 21 ++++++++++++++++++- .../web/dto/CommunityPostResponseDTO.java | 2 +- src/main/resources/application-dev.yml | 2 +- 6 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/main/java/gaji/service/domain/post/service/CommunityPostCommandService.java b/src/main/java/gaji/service/domain/post/service/CommunityPostCommandService.java index ea7ca245..aff2dc6c 100644 --- a/src/main/java/gaji/service/domain/post/service/CommunityPostCommandService.java +++ b/src/main/java/gaji/service/domain/post/service/CommunityPostCommandService.java @@ -9,6 +9,7 @@ public interface CommunityPostCommandService { CommnuityPost uploadPost(Long userId, CommunityPostRequestDTO.UploadPostRequestDTO request); + CommnuityPost editPost(Long userId, Long postId, CommunityPostRequestDTO.EditPostRequestDTO request); CommunityComment writeCommentOnCommunityPost(Long userId, Long postId, Long parentCommentId, CommunityPostRequestDTO.WriteCommentRequestDTO request); void hardDeleteComment(Long userId, Long commentId); void hardDeleteCommunityPost(Long userId, Long postId); diff --git a/src/main/java/gaji/service/domain/post/service/CommunityPostCommandServiceImpl.java b/src/main/java/gaji/service/domain/post/service/CommunityPostCommandServiceImpl.java index 3b328d12..a4b770bc 100644 --- a/src/main/java/gaji/service/domain/post/service/CommunityPostCommandServiceImpl.java +++ b/src/main/java/gaji/service/domain/post/service/CommunityPostCommandServiceImpl.java @@ -9,6 +9,7 @@ import gaji.service.domain.common.service.CategoryService; import gaji.service.domain.common.service.HashtagService; import gaji.service.domain.enums.CategoryEnum; +import gaji.service.domain.enums.PostTypeEnum; import gaji.service.domain.post.converter.CommunityPostConverter; import gaji.service.domain.post.entity.CommnuityPost; import gaji.service.domain.post.entity.CommunityComment; @@ -53,7 +54,7 @@ public CommnuityPost uploadPost(Long userId, CommunityPostRequestDTO.UploadPostR List hashtagStringList = request.getHashtagList(); List hashtagEntityList = hashtagService.createHashtagEntityList(hashtagStringList); - List selectHashtagList = HashtagConverter.toSelectHashtagList(hashtagEntityList, post.getId(), request.getType()); + List selectHashtagList = HashtagConverter.toSelectHashtagList(hashtagEntityList, post.getId(), PostTypeEnum.from(request.getType())); hashtagService.saveAllSelectHashtag(selectHashtagList); } @@ -70,6 +71,19 @@ public CommnuityPost uploadPost(Long userId, CommunityPostRequestDTO.UploadPostR return newPost; } + @Override + public CommnuityPost editPost(Long userId, Long postId, CommunityPostRequestDTO.EditPostRequestDTO request) { + // 조회 + CommnuityPost findPost = communityPostQueryService.findPostByPostId(postId); + + // 작성자 검증 + communityPostQueryService.validPostWriter(userId, findPost); + + + + return null; + } + @Override public CommunityComment writeCommentOnCommunityPost(Long userId, Long postId, Long parentCommentId, CommunityPostRequestDTO.WriteCommentRequestDTO request) { User findUser = userQueryService.findUserById(userId); diff --git a/src/main/java/gaji/service/domain/post/web/controller/CommunityPostRestController.java b/src/main/java/gaji/service/domain/post/web/controller/CommunityPostRestController.java index 02fedc61..adc71381 100644 --- a/src/main/java/gaji/service/domain/post/web/controller/CommunityPostRestController.java +++ b/src/main/java/gaji/service/domain/post/web/controller/CommunityPostRestController.java @@ -45,11 +45,21 @@ public class CommunityPostRestController { @PostMapping @Operation(summary = "커뮤니티 게시글 업로드 API", description = "커뮤니티의 게시글을 업로드하는 API입니다. 게시글 유형과 제목, 본문 내용을 검증합니다.") - public BaseResponse uploadPost(@RequestHeader("Authorization") String authorizationHeader, - @RequestBody @Valid CommunityPostRequestDTO.UploadPostRequestDTO request) { + public BaseResponse uploadPost(@RequestHeader("Authorization") String authorizationHeader, + @RequestBody @Valid CommunityPostRequestDTO.UploadPostRequestDTO request) { Long userId = tokenProviderService.getUserIdFromToken(authorizationHeader); CommnuityPost newPost = communityPostCommandService.uploadPost(userId, request); - return BaseResponse.onSuccess(CommunityPostConverter.toUploadPostResponseDTO(newPost)); + return BaseResponse.onSuccess(CommunityPostConverter.toPostIdResponseDTO(newPost)); + } + + @PutMapping("/{postId}") + @Operation(summary = "커뮤니티 게시글 수정 API", description = "커뮤니티 게시글을 수정 API입니다.") + public BaseResponse editPost(@RequestHeader("Authorization") String authorizationHeader, + @RequestBody @Valid CommunityPostRequestDTO.EditPostRequestDTO request, + @Min(value = 1, message = "postId는 1 이상 이어야 합니다.") @PathVariable Long postId) { + Long userId = tokenProviderService.getUserIdFromToken(authorizationHeader); + CommnuityPost editedCommnuityPost = communityPostCommandService.editPost(userId, postId, request); + return BaseResponse.onSuccess(CommunityPostConverter.toPostIdResponseDTO(editedCommnuityPost)); } @DeleteMapping("/{postId}") diff --git a/src/main/java/gaji/service/domain/post/web/dto/CommunityPostRequestDTO.java b/src/main/java/gaji/service/domain/post/web/dto/CommunityPostRequestDTO.java index 7322498c..e64278cd 100644 --- a/src/main/java/gaji/service/domain/post/web/dto/CommunityPostRequestDTO.java +++ b/src/main/java/gaji/service/domain/post/web/dto/CommunityPostRequestDTO.java @@ -32,7 +32,7 @@ public static class UploadPostRequestDTO { @Schema(description = "게시글 유형(프로젝트 모집, 질문, 블로그)") @ExistPostType - private final PostTypeEnum type; + private final String type; @Schema(description = "해시태그 리스트") @CheckHashtagBlank @@ -44,6 +44,25 @@ public static class UploadPostRequestDTO { private final String category; } + @Schema(description = "커뮤니티 게시글 수정 DTO") + @Getter + public static class EditPostRequestDTO { + @Schema(description = "게시글 제목") + private String title; + + @Schema(description = "게시글 본문") + private String body; + + @Schema(description = "카테고리") + @ExistsCategory + private String category; + + @Schema(description = "해시태그 리스트") + @CheckHashtagBlank + @CheckHashtagLength + private final List hashtagList = new ArrayList<>(); + } + @Schema(description = "커뮤니티 게시글 댓글 작성 DTO") @Getter @RequiredArgsConstructor diff --git a/src/main/java/gaji/service/domain/post/web/dto/CommunityPostResponseDTO.java b/src/main/java/gaji/service/domain/post/web/dto/CommunityPostResponseDTO.java index bcd2583c..e0405cff 100644 --- a/src/main/java/gaji/service/domain/post/web/dto/CommunityPostResponseDTO.java +++ b/src/main/java/gaji/service/domain/post/web/dto/CommunityPostResponseDTO.java @@ -18,7 +18,7 @@ public class CommunityPostResponseDTO { @Getter @NoArgsConstructor @AllArgsConstructor - public static class UploadPostResponseDTO { + public static class PostIdResponseDTO { Long postId; } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index d131c545..0f4bfc41 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -1,5 +1,5 @@ server: - port: 8000 + port: 8080 spring: application: