From afd7982f3f1147a2c11ce592be9b326d740ca0b5 Mon Sep 17 00:00:00 2001 From: OJOJIN Date: Fri, 12 Jan 2024 15:44:32 +0900 Subject: [PATCH 1/9] =?UTF-8?q?[feat]=20#37=20=EA=B2=8C=EC=8B=9C=EA=B8=80?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20api=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/controller/PostController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java b/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java index eeb88fd..d59c76f 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java +++ b/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java @@ -3,8 +3,12 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.gachon.checkmate.domain.post.dto.request.PostCreateRequestDto; +import org.gachon.checkmate.domain.post.dto.request.PostUpdateRequestDto; +import org.gachon.checkmate.domain.post.dto.request.PostStateUpdateRequestDto; import org.gachon.checkmate.domain.post.dto.response.PostDetailResponseDto; import org.gachon.checkmate.domain.post.dto.response.PostSearchResponseDto; +import org.gachon.checkmate.domain.post.dto.response.PostStateUpdateResponseDto; +import org.gachon.checkmate.domain.post.dto.response.PostUpdateResponseDto; import org.gachon.checkmate.domain.post.service.PostService; import org.gachon.checkmate.global.common.SuccessResponse; import org.gachon.checkmate.global.config.auth.UserId; @@ -50,6 +54,14 @@ public ResponseEntity> getMyPosts(@UserId final Long userId, return SuccessResponse.ok(responseDto); } + @PatchMapping("{id}") + public ResponseEntity> updateMyPost(@UserId final Long userId, + @PathVariable("id") final Long postId, + @RequestBody @Valid final PostUpdateRequestDto requestDto) { + PostUpdateResponseDto responseDto = postService.updateMyPost(userId, postId, requestDto); + return SuccessResponse.ok(responseDto); + } + @PostMapping public ResponseEntity> createPost(@UserId final Long userId, @RequestBody @Valid final PostCreateRequestDto requestDto) { From 53c7dd63072f8042cb92cb6409f11ecc42276511 Mon Sep 17 00:00:00 2001 From: OJOJIN Date: Fri, 12 Jan 2024 15:44:41 +0900 Subject: [PATCH 2/9] =?UTF-8?q?[feat]=20#37=20=EA=B2=8C=EC=8B=9C=EA=B8=80?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20api=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/service/PostService.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java b/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java index 831bcef..08db313 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java +++ b/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java @@ -10,9 +10,9 @@ import org.gachon.checkmate.domain.member.entity.User; import org.gachon.checkmate.domain.member.repository.UserRepository; import org.gachon.checkmate.domain.post.dto.request.PostCreateRequestDto; -import org.gachon.checkmate.domain.post.dto.response.PostDetailResponseDto; -import org.gachon.checkmate.domain.post.dto.response.PostSearchElementResponseDto; -import org.gachon.checkmate.domain.post.dto.response.PostSearchResponseDto; +import org.gachon.checkmate.domain.post.dto.request.PostUpdateRequestDto; +import org.gachon.checkmate.domain.post.dto.request.PostStateUpdateRequestDto; +import org.gachon.checkmate.domain.post.dto.response.*; import org.gachon.checkmate.domain.post.dto.support.PostDetailDto; import org.gachon.checkmate.domain.post.dto.support.PostPagingSearchCondition; import org.gachon.checkmate.domain.post.dto.support.PostSearchCondition; @@ -22,6 +22,7 @@ import org.gachon.checkmate.domain.post.repository.PostRepository; import org.gachon.checkmate.domain.scrap.repository.ScrapRepository; import org.gachon.checkmate.global.error.exception.EntityNotFoundException; +import org.gachon.checkmate.global.error.exception.ForbiddenException; import org.gachon.checkmate.global.error.exception.InvalidValueException; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -90,6 +91,22 @@ public PostSearchResponseDto searchTextPost(Long userId, String text, Pageable p return PostSearchResponseDto.of(searchResults, postSearchList.getTotalPages(), postSearchList.getTotalElements()); } + public PostUpdateResponseDto updateMyPost(Long userId, Long postId, PostUpdateRequestDto requestDto) { + User user = getUserOrThrow(userId); + Post post = getPostOrThrow(postId); + validatePostWriter(user, post); + validateAvailableEndDate(requestDto.endDate()); + post.updatePost(requestDto); + CheckListResponseDto checkListResponseDto = createCheckListResponseDto(post.getPostCheckList()); + return PostUpdateResponseDto.of(post, checkListResponseDto); + } + + private void validatePostWriter(User user, Post post) { + if(!post.getUser().getId().equals(user.getId())) { + throw new ForbiddenException(NOT_POST_WRITER); + } + } + private List createPostSearchResponseDto(Page postSearchDtoList, CheckList checkList) { return postSearchDtoList.stream() .map(postSearchDto -> @@ -193,4 +210,9 @@ private User getUserOrThrow(Long userId) { private boolean existPostInScrap(Long postId, Long userId) { return scrapRepository.existsByPostIdAndUserId(postId, userId); } + + private Post getPostOrThrow(Long postId) { + return postRepository.findById(postId) + .orElseThrow(() -> new EntityNotFoundException(POST_NOT_FOUND)); + } } From a357bb424b1998523230ea1c32b2736c37c85529 Mon Sep 17 00:00:00 2001 From: OJOJIN Date: Fri, 12 Jan 2024 15:45:07 +0900 Subject: [PATCH 3/9] =?UTF-8?q?[feat]=20#37=20Post,=20PostCheckList=20upda?= =?UTF-8?q?te=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/checkList/entity/PostCheckList.java | 11 ++++++++++- .../gachon/checkmate/domain/post/entity/Post.java | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gachon/checkmate/domain/checkList/entity/PostCheckList.java b/src/main/java/org/gachon/checkmate/domain/checkList/entity/PostCheckList.java index abc195e..f6d36ff 100644 --- a/src/main/java/org/gachon/checkmate/domain/checkList/entity/PostCheckList.java +++ b/src/main/java/org/gachon/checkmate/domain/checkList/entity/PostCheckList.java @@ -46,4 +46,13 @@ public static PostCheckList createPostCheckList(CheckListRequestDto checkListReq post.setPostCheckList(checkList); return checkList; } -} \ No newline at end of file + + public void updatePostCheckList(CheckListRequestDto checkListRequestDto) { + this.cleanType = checkListRequestDto.cleanType(); + this.drinkType = checkListRequestDto.drinkType(); + this.homeType = checkListRequestDto.homeType(); + this.lifePatterType = checkListRequestDto.lifePatterType(); + this.noiseType = checkListRequestDto.noiseType(); + this.sleepType = checkListRequestDto.sleepType(); + } +} diff --git a/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java b/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java index 07518df..9a0cd46 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java +++ b/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java @@ -9,6 +9,8 @@ import org.gachon.checkmate.domain.post.converter.RoomTypeConverter; import org.gachon.checkmate.domain.post.converter.SimilarityKeyTypeConverter; import org.gachon.checkmate.domain.post.dto.request.PostCreateRequestDto; +import org.gachon.checkmate.domain.post.dto.request.PostStateUpdateRequestDto; +import org.gachon.checkmate.domain.post.dto.request.PostUpdateRequestDto; import org.gachon.checkmate.domain.scrap.entity.Scrap; import org.gachon.checkmate.global.common.BaseTimeEntity; @@ -51,6 +53,7 @@ public static Post createPost(PostCreateRequestDto postCreateRequestDto, User us .title(postCreateRequestDto.title()) .content(postCreateRequestDto.content()) .endDate(postCreateRequestDto.endDate()) + .postState(PostState.RECRUITING) .roomType(postCreateRequestDto.roomType()) .importantKeyType(postCreateRequestDto.importantKey()) .similarityKeyType(postCreateRequestDto.similarityKey()) @@ -67,4 +70,15 @@ public void setPostCheckList(PostCheckList postCheckList) { public void addScrap(Scrap scrap) { this.scrapList.add(scrap); } + + public void updatePost(PostUpdateRequestDto postUpdateRequestDto) { + this.title = postUpdateRequestDto.title(); + this.content = postUpdateRequestDto.content(); + this.importantKeyType = postUpdateRequestDto.importantKey(); + this.similarityKeyType = postUpdateRequestDto.similarityKey(); + this.roomType = postUpdateRequestDto.roomType(); + this.endDate = postUpdateRequestDto.endDate(); + this.postCheckList.updatePostCheckList(postUpdateRequestDto.checkList()); + } + } From 49c74e413d36d8ebf6c19dcff0eb07aa06ea6090 Mon Sep 17 00:00:00 2001 From: OJOJIN Date: Fri, 12 Jan 2024 15:45:25 +0900 Subject: [PATCH 4/9] =?UTF-8?q?[feat]=20#37=20=EA=B2=8C=EC=8B=9C=EB=AC=BC?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=EA=B6=8C=ED=95=9C=20=EC=97=86=EC=9D=8C=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/gachon/checkmate/global/error/ErrorCode.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java b/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java index c4ea46c..3dabc65 100644 --- a/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java +++ b/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java @@ -35,6 +35,7 @@ public enum ErrorCode { * 403 Forbidden */ FORBIDDEN(HttpStatus.FORBIDDEN, "리소스 접근 권한이 없습니다."), + NOT_POST_WRITER(HttpStatus.FORBIDDEN, "게시물을 수정할 권한이 없습니다. 작성자만이 게시물을 수정할 수 있습니다."), /** * 404 Not Found From 70ae83125144460294acee968ed70605644996ec Mon Sep 17 00:00:00 2001 From: OJOJIN Date: Fri, 12 Jan 2024 15:45:39 +0900 Subject: [PATCH 5/9] =?UTF-8?q?[feat]=20#37=20=EA=B2=8C=EC=8B=9C=EB=AC=BC?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/PostUpdateRequestDto.java | 21 ++++++++++++ .../dto/response/PostUpdateResponseDto.java | 32 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/post/dto/request/PostUpdateRequestDto.java create mode 100644 src/main/java/org/gachon/checkmate/domain/post/dto/response/PostUpdateResponseDto.java diff --git a/src/main/java/org/gachon/checkmate/domain/post/dto/request/PostUpdateRequestDto.java b/src/main/java/org/gachon/checkmate/domain/post/dto/request/PostUpdateRequestDto.java new file mode 100644 index 0000000..dbfb18d --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/post/dto/request/PostUpdateRequestDto.java @@ -0,0 +1,21 @@ +package org.gachon.checkmate.domain.post.dto.request; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import org.gachon.checkmate.domain.checkList.dto.request.CheckListRequestDto; +import org.gachon.checkmate.domain.post.entity.ImportantKeyType; +import org.gachon.checkmate.domain.post.entity.RoomType; +import org.gachon.checkmate.domain.post.entity.SimilarityKeyType; + +import java.time.LocalDate; + +public record PostUpdateRequestDto( + @NotBlank(message = "제목을 입력해주세요") String title, + @NotBlank(message = "내용을 입력해주세요") String content, + @NotNull(message = "중요 키워드를 입력해주세요") ImportantKeyType importantKey, + @NotNull(message = "유사도를 입력해주세요") SimilarityKeyType similarityKey, + @NotNull(message = "기숙사 유형을 입력해주세요") RoomType roomType, + @NotNull(message = "모집 마감기간을 입력해주세요") LocalDate endDate, + @NotNull(message = "체크리스트를 입력해주세요") CheckListRequestDto checkList +) { +} diff --git a/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostUpdateResponseDto.java b/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostUpdateResponseDto.java new file mode 100644 index 0000000..eee2887 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostUpdateResponseDto.java @@ -0,0 +1,32 @@ +package org.gachon.checkmate.domain.post.dto.response; + +import lombok.Builder; +import org.gachon.checkmate.domain.checkList.dto.response.CheckListResponseDto; +import org.gachon.checkmate.domain.post.entity.Post; + +import java.time.LocalDate; + +@Builder +public record PostUpdateResponseDto( + Long postId, + String title, + String content, + String importantKey, + String similarityKey, + String roomType, + LocalDate endDate, + CheckListResponseDto checkList +) { + public static PostUpdateResponseDto of(Post post, CheckListResponseDto checkListResponseDto) { + return PostUpdateResponseDto.builder() + .postId(post.getId()) + .title(post.getTitle()) + .content(post.getContent()) + .importantKey(post.getImportantKeyType().getDesc()) + .similarityKey(post.getSimilarityKeyType().getDesc()) + .roomType(post.getRoomType().getDesc()) + .checkList(checkListResponseDto) + .build(); + } +} + From 54bd0e4d0f8d41f55563ab422bf41744c1982946 Mon Sep 17 00:00:00 2001 From: OJOJIN Date: Fri, 12 Jan 2024 15:46:41 +0900 Subject: [PATCH 6/9] =?UTF-8?q?[feat]=20#37=20=EA=B2=8C=EC=8B=9C=EB=AC=BC?= =?UTF-8?q?=20=EB=AA=A8=EC=A7=91=20=EC=83=81=ED=83=9C=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20api=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../checkmate/domain/post/controller/PostController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java b/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java index d59c76f..148816f 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java +++ b/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java @@ -62,6 +62,14 @@ public ResponseEntity> updateMyPost(@UserId final Long userId return SuccessResponse.ok(responseDto); } + @PatchMapping("/state/{id}") + public ResponseEntity> updatePostState(@UserId final Long userId, + @PathVariable("id") final Long postId, + @RequestBody @Valid final PostStateUpdateRequestDto requestDto) { + PostStateUpdateResponseDto responseDto = postService.updateMyPostState(userId, postId, requestDto); + return SuccessResponse.ok(responseDto); + } + @PostMapping public ResponseEntity> createPost(@UserId final Long userId, @RequestBody @Valid final PostCreateRequestDto requestDto) { From fc28c57ade0f5b4019ae39f1c3cb6a4261a89ba8 Mon Sep 17 00:00:00 2001 From: OJOJIN Date: Fri, 12 Jan 2024 15:46:49 +0900 Subject: [PATCH 7/9] =?UTF-8?q?[feat]=20#37=20=EA=B2=8C=EC=8B=9C=EB=AC=BC?= =?UTF-8?q?=20=EB=AA=A8=EC=A7=91=20=EC=83=81=ED=83=9C=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20api=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gachon/checkmate/domain/post/service/PostService.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java b/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java index 08db313..76108af 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java +++ b/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java @@ -101,6 +101,14 @@ public PostUpdateResponseDto updateMyPost(Long userId, Long postId, PostUpdateRe return PostUpdateResponseDto.of(post, checkListResponseDto); } + public PostStateUpdateResponseDto updateMyPostState(Long userId, Long postId, PostStateUpdateRequestDto requestDto) { + User user = getUserOrThrow(userId); + Post post = getPostOrThrow(postId); + validatePostWriter(user, post); + post.updatePostState(requestDto); + return PostStateUpdateResponseDto.of(post); + } + private void validatePostWriter(User user, Post post) { if(!post.getUser().getId().equals(user.getId())) { throw new ForbiddenException(NOT_POST_WRITER); From 6ef77b5a9a0423371d81a660acb8b20128c88f4a Mon Sep 17 00:00:00 2001 From: OJOJIN Date: Fri, 12 Jan 2024 15:47:13 +0900 Subject: [PATCH 8/9] =?UTF-8?q?[feat]=20#37=20Post=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EB=AC=BC=20=EB=AA=A8=EC=A7=91=20=EC=83=81=ED=83=9C=20update=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/gachon/checkmate/domain/post/entity/Post.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java b/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java index 9a0cd46..68c6e29 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java +++ b/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java @@ -81,4 +81,7 @@ public void updatePost(PostUpdateRequestDto postUpdateRequestDto) { this.postCheckList.updatePostCheckList(postUpdateRequestDto.checkList()); } + public void updatePostState(PostStateUpdateRequestDto postStateUpdateRequestDto) { + this.postState = postStateUpdateRequestDto.postState(); + } } From a3f5deedacb9300603e98c6d4b0ffdfa4cd787ab Mon Sep 17 00:00:00 2001 From: OJOJIN Date: Fri, 12 Jan 2024 15:47:23 +0900 Subject: [PATCH 9/9] =?UTF-8?q?[feat]=20#37=20Post=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EB=AC=BC=20=EB=AA=A8=EC=A7=91=20=EC=83=81=ED=83=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/PostStateUpdateRequestDto.java | 9 +++++++++ .../response/PostStateUpdateResponseDto.java | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/post/dto/request/PostStateUpdateRequestDto.java create mode 100644 src/main/java/org/gachon/checkmate/domain/post/dto/response/PostStateUpdateResponseDto.java diff --git a/src/main/java/org/gachon/checkmate/domain/post/dto/request/PostStateUpdateRequestDto.java b/src/main/java/org/gachon/checkmate/domain/post/dto/request/PostStateUpdateRequestDto.java new file mode 100644 index 0000000..7664380 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/post/dto/request/PostStateUpdateRequestDto.java @@ -0,0 +1,9 @@ +package org.gachon.checkmate.domain.post.dto.request; + +import jakarta.validation.constraints.NotNull; +import org.gachon.checkmate.domain.post.entity.PostState; + +public record PostStateUpdateRequestDto( + @NotNull(message = "게시글 상태를 입력해주세요") PostState postState +) { +} diff --git a/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostStateUpdateResponseDto.java b/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostStateUpdateResponseDto.java new file mode 100644 index 0000000..8e22647 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostStateUpdateResponseDto.java @@ -0,0 +1,17 @@ +package org.gachon.checkmate.domain.post.dto.response; + +import lombok.Builder; +import org.gachon.checkmate.domain.post.entity.Post; + +@Builder +public record PostStateUpdateResponseDto ( + Long postId, + String postState +) { + public static PostStateUpdateResponseDto of(Post post) { + return PostStateUpdateResponseDto.builder() + .postId(post.getId()) + .postState(post.getPostState().getDesc()) + .build(); + } +}