From d0ce294eec90f558e2f9184c0f3375b99e315965 Mon Sep 17 00:00:00 2001 From: strongmhk Date: Wed, 21 Aug 2024 18:04:34 +0900 Subject: [PATCH 1/8] =?UTF-8?q?:bug:=20[#148]=20fix:=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EA=B8=80=20=EC=9C=A0=ED=98=95=20=EA=B2=80=EC=A6=9D=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gaji/service/domain/enums/PostTypeEnum.java | 2 +- .../post/converter/CommunityPostConverter.java | 13 +++++++------ .../post/converter/PostTypeConverter.java | 8 +++++++- .../post/validation/PostTypeExistValidator.java | 17 +++-------------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/main/java/gaji/service/domain/enums/PostTypeEnum.java b/src/main/java/gaji/service/domain/enums/PostTypeEnum.java index 74c60b1f..8ac84b43 100644 --- a/src/main/java/gaji/service/domain/enums/PostTypeEnum.java +++ b/src/main/java/gaji/service/domain/enums/PostTypeEnum.java @@ -28,7 +28,7 @@ public static PostTypeEnum from(String param) { } } log.error("PostTypeEnum.from() exception occur param: {}", param); - throw new RestApiException(CommunityPostErrorStatus._INVALID_POST_TYPE); + return null; } } diff --git a/src/main/java/gaji/service/domain/post/converter/CommunityPostConverter.java b/src/main/java/gaji/service/domain/post/converter/CommunityPostConverter.java index f86408f0..37147d5e 100644 --- a/src/main/java/gaji/service/domain/post/converter/CommunityPostConverter.java +++ b/src/main/java/gaji/service/domain/post/converter/CommunityPostConverter.java @@ -41,8 +41,8 @@ public static PostStatusEnum getInitialPostStatus(PostTypeEnum type) { (type == PostTypeEnum.PROJECT) ? PostStatusEnum.RECRUITING : PostStatusEnum.BLOGING; } - public static CommunityPostResponseDTO.UploadPostResponseDTO toUploadPostResponseDTO(CommnuityPost post) { - return CommunityPostResponseDTO.UploadPostResponseDTO + public static CommunityPostResponseDTO.PostIdResponseDTO toPostIdResponseDTO(CommnuityPost post) { + return CommunityPostResponseDTO.PostIdResponseDTO .builder() .postId(post.getId()) .build(); @@ -63,14 +63,15 @@ public static CommunityPostResponseDTO.PostLikesIdDTO toPostLikesIdDTO(PostLikes } public static CommnuityPost toPost(CommunityPostRequestDTO.UploadPostRequestDTO request, User user) { + PostTypeEnum postTypeEnum = PostTypeEnum.from(request.getType()); + return CommnuityPost.builder() .user(user) .title(request.getTitle()) .body(request.getBody()) - .thumbnailUrl(/*(request.getThumbnailUrl() == null) ? Post.getDefaultThumbnailUrl() : request.getThumbnailUrl()*/ - request.getThumbnailUrl()) - .type(request.getType()) - .status(getInitialPostStatus(request.getType())) + .thumbnailUrl(request.getThumbnailUrl()) + .type(postTypeEnum) + .status(getInitialPostStatus(postTypeEnum)) .build(); } diff --git a/src/main/java/gaji/service/domain/post/converter/PostTypeConverter.java b/src/main/java/gaji/service/domain/post/converter/PostTypeConverter.java index cb9b6392..9eda4b61 100644 --- a/src/main/java/gaji/service/domain/post/converter/PostTypeConverter.java +++ b/src/main/java/gaji/service/domain/post/converter/PostTypeConverter.java @@ -1,12 +1,18 @@ package gaji.service.domain.post.converter; import gaji.service.domain.enums.PostTypeEnum; +import gaji.service.domain.post.code.CommunityPostErrorStatus; +import gaji.service.global.exception.RestApiException; import org.springframework.core.convert.converter.Converter; public class PostTypeConverter implements Converter { @Override public PostTypeEnum convert(String param) { - return PostTypeEnum.from(param); + PostTypeEnum postType = PostTypeEnum.from(param); + if (postType == null) { + throw new RestApiException(CommunityPostErrorStatus._INVALID_POST_TYPE); + } + return postType; } } diff --git a/src/main/java/gaji/service/domain/post/validation/PostTypeExistValidator.java b/src/main/java/gaji/service/domain/post/validation/PostTypeExistValidator.java index 58b8ec5c..c112ea9e 100644 --- a/src/main/java/gaji/service/domain/post/validation/PostTypeExistValidator.java +++ b/src/main/java/gaji/service/domain/post/validation/PostTypeExistValidator.java @@ -8,27 +8,16 @@ import org.springframework.stereotype.Component; @Component -public class PostTypeExistValidator implements ConstraintValidator { +public class PostTypeExistValidator implements ConstraintValidator { @Override public void initialize(ExistPostType constraintAnnotation) { ConstraintValidator.super.initialize(constraintAnnotation); } - // TODO: 검증 메시지 적용 안되는 문제 해결하기 @Override - public boolean isValid(PostTypeEnum value, ConstraintValidatorContext context) { - boolean isValid = (value == PostTypeEnum.ROOM) || (value == PostTypeEnum.BLOG) || (value == PostTypeEnum.PROJECT) || (value == PostTypeEnum.QUESTION); -// boolean isValid = false; -// -// for (PostTypeEnum postTypeEnum : PostTypeEnum.values()) { -// if (postTypeEnum.equals(value)) { -// isValid = true; -// } -// } - -// boolean isValid = Arrays.stream(PostTypeEnum.values()) -// .allMatch(postTypeEnum -> postTypeEnum.equals(value)); + public boolean isValid(String value, ConstraintValidatorContext context) { + boolean isValid = PostTypeEnum.from(value) != null; if (!isValid) { context.disableDefaultConstraintViolation(); From 34ca10be00eecd84dfb3d5e25081f5d10978351f Mon Sep 17 00:00:00 2001 From: strongmhk Date: Thu, 22 Aug 2024 10:42:57 +0900 Subject: [PATCH 2/8] =?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: From a2e9d21d41b9267f358aca537553c52dc7a76f6b Mon Sep 17 00:00:00 2001 From: strongmhk Date: Thu, 26 Sep 2024 17:31:57 +0900 Subject: [PATCH 3/8] =?UTF-8?q?:recycle:=20[#148]=20refactor:=20CommunityP?= =?UTF-8?q?ost=20=EA=B4=80=EB=A0=A8=20API=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 서비스 단에서 DTO를 반환하도록 변경 --- .gitignore | 5 +- .../converter/CommunityPostConverter.java | 27 ++--------- .../service/CommunityPostCommandService.java | 5 +- .../CommunityPostCommandServiceImpl.java | 7 +-- .../service/CommunityPostQueryService.java | 5 +- .../CommunityPostQueryServiceImpl.java | 47 +++++++++++++++++-- .../CommunityPostRestController.java | 15 +++--- 7 files changed, 68 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index f223dc57..ca734669 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,7 @@ out/ .vscode/ ### application files ### -application.yml \ No newline at end of file +application.yml + +# 맥에서 생성되는 ds_store +.DS_Store \ No newline at end of file diff --git a/src/main/java/gaji/service/domain/post/converter/CommunityPostConverter.java b/src/main/java/gaji/service/domain/post/converter/CommunityPostConverter.java index 37147d5e..f06af6bf 100644 --- a/src/main/java/gaji/service/domain/post/converter/CommunityPostConverter.java +++ b/src/main/java/gaji/service/domain/post/converter/CommunityPostConverter.java @@ -29,11 +29,6 @@ @RequiredArgsConstructor @Component public class CommunityPostConverter { - private final HashtagService hashtagService; - private final CategoryService categoryService; - private final CommunityPostBookMarkService postBookMarkService; - private final CommunityPostLikesService postLikesService; - private final CommunityPostQueryService communityPostQueryService; // 초기 PostStatus 지정 public static PostStatusEnum getInitialPostStatus(PostTypeEnum type) { @@ -98,8 +93,7 @@ public static PostLikes toPostLikes(User user, CommnuityPost post) { .build(); } - public CommunityPostResponseDTO.PostPreviewDTO toPostPreviewDTO(CommnuityPost post) { - List selectHashtagList = hashtagService.findAllFetchJoinWithHashtagByEntityIdAndPostType(post.getId(), post.getType()); + public static CommunityPostResponseDTO.PostPreviewDTO toPostPreviewDTO(CommnuityPost post, List selectHashtagList) { List hashtagList = HashtagConverter.toHashtagNameList(selectHashtagList); return CommunityPostResponseDTO.PostPreviewDTO.builder() @@ -118,10 +112,9 @@ public CommunityPostResponseDTO.PostPreviewDTO toPostPreviewDTO(CommnuityPost po .build(); } - public CommunityPostResponseDTO.PostPreviewListDTO toPostPreviewListDTO(List postList, boolean hasNext) { - CommunityPostConverter postConverter = new CommunityPostConverter(hashtagService, categoryService, postBookMarkService, postLikesService, communityPostQueryService); + public static CommunityPostResponseDTO.PostPreviewListDTO toPostPreviewListDTO(List postList, boolean hasNext, List selectHashtagList) { List postPreviewDTOList = postList.stream() - .map(postConverter::toPostPreviewDTO) + .map(post -> CommunityPostConverter.toPostPreviewDTO(post, selectHashtagList)) .collect(Collectors.toList()); return CommunityPostResponseDTO.PostPreviewListDTO.builder() @@ -130,20 +123,10 @@ public CommunityPostResponseDTO.PostPreviewListDTO toPostPreviewListDTO(List selectHashtagList = hashtagService.findAllFetchJoinWithHashtagByEntityIdAndPostType(post.getId(), post.getType()); + public static CommunityPostResponseDTO.PostDetailDTO toPostDetailDTO(CommnuityPost post, SelectCategory selectCategory, List selectHashtagList, + boolean isBookmarked, boolean isLiked, boolean isWriter) { List hashtagNameAndIdDTOList = HashtagConverter.toHashtagNameAndIdDTOList(selectHashtagList); - // ofNullable 메서드로 NPE 방지 - /*CategoryEnum category = Optional.ofNullable(categoryService.findOneFetchJoinWithCategoryByEntityIdAndPostType(post.getId(), post.getType())) - .map(SelectCategory::getCategory) - .map(Category::getCategory) - .orElse(null);*/ - - boolean isBookmarked = (userId == null) ? false : postBookMarkService.existsByUserAndPost(userId, post); - boolean isLiked = (userId == null) ? false : postLikesService.existsByUserAndPost(userId, post); - boolean isWriter = (userId == null) ? false : communityPostQueryService.isPostWriter(userId, post); - return CommunityPostResponseDTO.PostDetailDTO.builder() .userId(post.getUser().getId()) .type(post.getType()) 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 aff2dc6c..357cf6cf 100644 --- a/src/main/java/gaji/service/domain/post/service/CommunityPostCommandService.java +++ b/src/main/java/gaji/service/domain/post/service/CommunityPostCommandService.java @@ -5,11 +5,12 @@ import gaji.service.domain.post.entity.PostBookmark; import gaji.service.domain.post.entity.PostLikes; import gaji.service.domain.post.web.dto.CommunityPostRequestDTO; +import gaji.service.domain.post.web.dto.CommunityPostResponseDTO; public interface CommunityPostCommandService { - CommnuityPost uploadPost(Long userId, CommunityPostRequestDTO.UploadPostRequestDTO request); - CommnuityPost editPost(Long userId, Long postId, CommunityPostRequestDTO.EditPostRequestDTO request); + CommunityPostResponseDTO.PostIdResponseDTO uploadPost(Long userId, CommunityPostRequestDTO.UploadPostRequestDTO request); + CommunityPostResponseDTO.PostIdResponseDTO 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 a4b770bc..76878e39 100644 --- a/src/main/java/gaji/service/domain/post/service/CommunityPostCommandServiceImpl.java +++ b/src/main/java/gaji/service/domain/post/service/CommunityPostCommandServiceImpl.java @@ -19,6 +19,7 @@ import gaji.service.domain.post.repository.CommunityPostJpaRepository; import gaji.service.domain.post.repository.CommunityPostLikesRepository; import gaji.service.domain.post.web.dto.CommunityPostRequestDTO; +import gaji.service.domain.post.web.dto.CommunityPostResponseDTO; import gaji.service.domain.user.entity.User; import gaji.service.domain.user.service.UserQueryService; import lombok.RequiredArgsConstructor; @@ -43,7 +44,7 @@ public class CommunityPostCommandServiceImpl implements CommunityPostCommandServ @Override - public CommnuityPost uploadPost(Long userId, CommunityPostRequestDTO.UploadPostRequestDTO request) { + public CommunityPostResponseDTO.PostIdResponseDTO uploadPost(Long userId, CommunityPostRequestDTO.UploadPostRequestDTO request) { User findUser = userQueryService.findUserById(userId); CommnuityPost post = CommunityPostConverter.toPost(request, findUser); CommnuityPost newPost = communityPostJpaRepository.save(post); @@ -68,11 +69,11 @@ public CommnuityPost uploadPost(Long userId, CommunityPostRequestDTO.UploadPostR categoryService.saveSelectCategory(selectCategory); } - return newPost; + return CommunityPostConverter.toPostIdResponseDTO(newPost); } @Override - public CommnuityPost editPost(Long userId, Long postId, CommunityPostRequestDTO.EditPostRequestDTO request) { + public CommunityPostResponseDTO.PostIdResponseDTO editPost(Long userId, Long postId, CommunityPostRequestDTO.EditPostRequestDTO request) { // 조회 CommnuityPost findPost = communityPostQueryService.findPostByPostId(postId); diff --git a/src/main/java/gaji/service/domain/post/service/CommunityPostQueryService.java b/src/main/java/gaji/service/domain/post/service/CommunityPostQueryService.java index 3a06924c..07c203f7 100644 --- a/src/main/java/gaji/service/domain/post/service/CommunityPostQueryService.java +++ b/src/main/java/gaji/service/domain/post/service/CommunityPostQueryService.java @@ -4,13 +4,14 @@ import gaji.service.domain.enums.PostTypeEnum; import gaji.service.domain.enums.SortType; import gaji.service.domain.post.entity.CommnuityPost; +import gaji.service.domain.post.web.dto.CommunityPostResponseDTO; import org.springframework.data.domain.Slice; public interface CommunityPostQueryService { CommnuityPost findPostByPostId(Long postId); - Slice getPostList(String keyword, + CommunityPostResponseDTO.PostPreviewListDTO getPostList(String keyword, Integer lastPopularityScore, Long lastPostId, Integer lastLikeCnt, @@ -21,7 +22,7 @@ Slice getPostList(String keyword, PostStatusEnum filter, int page, int size); - CommnuityPost getPostDetail(Long postId); + CommunityPostResponseDTO.PostDetailDTO getPostDetail(Long userId, Long postId); boolean isPostWriter(Long userId, CommnuityPost post); void validPostWriter(Long userId, CommnuityPost post); void validExistsPostLikes(Long userId, CommnuityPost post); diff --git a/src/main/java/gaji/service/domain/post/service/CommunityPostQueryServiceImpl.java b/src/main/java/gaji/service/domain/post/service/CommunityPostQueryServiceImpl.java index 149c5a39..38d53318 100644 --- a/src/main/java/gaji/service/domain/post/service/CommunityPostQueryServiceImpl.java +++ b/src/main/java/gaji/service/domain/post/service/CommunityPostQueryServiceImpl.java @@ -1,15 +1,20 @@ package gaji.service.domain.post.service; +import gaji.service.domain.common.entity.SelectCategory; +import gaji.service.domain.common.entity.SelectHashtag; 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.PostStatusEnum; import gaji.service.domain.enums.PostTypeEnum; import gaji.service.domain.enums.SortType; import gaji.service.domain.post.code.CommunityPostErrorStatus; +import gaji.service.domain.post.converter.CommunityPostConverter; import gaji.service.domain.post.entity.CommnuityPost; import gaji.service.domain.post.repository.CommunityPostBookmarkRepository; import gaji.service.domain.post.repository.CommunityPostJpaRepository; import gaji.service.domain.post.repository.CommunityPostLikesRepository; +import gaji.service.domain.post.web.dto.CommunityPostResponseDTO; import gaji.service.global.exception.RestApiException; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.PageRequest; @@ -17,6 +22,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.List; + @Service @RequiredArgsConstructor @Transactional(readOnly = true) @@ -26,9 +34,16 @@ public class CommunityPostQueryServiceImpl implements CommunityPostQueryService private final CommunityPostBookmarkRepository postBookmarkRepository; private final CategoryService categoryService; + private final HashtagService hashtagService; + private final CommunityPostBookMarkService postBookMarkService; + private final CommunityPostLikesService postLikesService; + private final CommunityPostQueryService communityPostQueryService; + + private final CommunityPostConverter communityPostConverter; + @Override - public Slice getPostList(String keyword, + public CommunityPostResponseDTO.PostPreviewListDTO getPostList(String keyword, Integer lastPopularityScore, Long lastPostId, Integer lastLikeCnt, @@ -48,7 +63,7 @@ public Slice getPostList(String keyword, categoryId=categoryService.findAllByCategory(CategoryEnum.fromValue(category)).get(0).getId(); } - return communityPostJpaRepository.findAllFetchJoinWithUser(keyword, + Slice postSlice = communityPostJpaRepository.findAllFetchJoinWithUser(keyword, lastPopularityScore, lastPostId, lastLikeCnt, @@ -58,17 +73,41 @@ public Slice getPostList(String keyword, categoryId, sortType, pageRequest); + + List postPreviewDTOList = new ArrayList<>(); + + for (CommnuityPost post : postSlice.getContent()) { + List selectHashtagList = hashtagService.findAllFetchJoinWithHashtagByEntityIdAndPostType(post.getId(), post.getType()); + postPreviewDTOList.add(CommunityPostConverter.toPostPreviewDTO(post, selectHashtagList)); + } + + return CommunityPostResponseDTO.PostPreviewListDTO.builder() + .postList(postPreviewDTOList) + .hasNext(postSlice.hasNext()) + .build(); +// return CommunityPostConverter.toPostPreviewListDTO(postSlice.getContent(), postSlice.hasNext(), selectHashtagList); } @Override - public CommnuityPost getPostDetail(Long postId) { + public CommunityPostResponseDTO.PostDetailDTO getPostDetail(Long userId, Long postId) { CommnuityPost findPost = communityPostJpaRepository.findByIdFetchJoinWithUser(postId); if (findPost == null) { throw new RestApiException(CommunityPostErrorStatus._POST_NOT_FOUND); } + + boolean isBookmarked = (userId == null) ? false : postBookMarkService.existsByUserAndPost(userId, findPost); + boolean isLiked = (userId == null) ? false : postLikesService.existsByUserAndPost(userId, findPost); + boolean isWriter = (userId == null) ? false : communityPostQueryService.isPostWriter(userId, findPost); + + SelectCategory category = categoryService.findByEntityIdAndType(findPost.getId(), findPost.getType()); + + List selectHashtagList = hashtagService.findAllFetchJoinWithHashtagByEntityIdAndPostType(findPost.getId(), findPost.getType()); + + CommunityPostResponseDTO.PostDetailDTO postDetailDTO = CommunityPostConverter.toPostDetailDTO(findPost, category, selectHashtagList, isBookmarked, isLiked, isWriter); + findPost.increaseHitCnt(); findPost.increasePopularityScoreByHit(); - return findPost; + return postDetailDTO; } @Override 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 adc71381..7b28144f 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 @@ -48,8 +48,8 @@ public class CommunityPostRestController { 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.toPostIdResponseDTO(newPost)); + CommunityPostResponseDTO.PostIdResponseDTO newPost = communityPostCommandService.uploadPost(userId, request); + return BaseResponse.onSuccess(newPost); } @PutMapping("/{postId}") @@ -58,8 +58,8 @@ public BaseResponse editPost(@Reques @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)); + CommunityPostResponseDTO.PostIdResponseDTO editedCommnuityPost = communityPostCommandService.editPost(userId, postId, request); + return BaseResponse.onSuccess(editedCommnuityPost); } @DeleteMapping("/{postId}") @@ -82,9 +82,7 @@ public BaseResponse hardDeleteCommunityPost(@RequestHeader("Authorization") Stri public BaseResponse getPostDetail(@Min(value = 1, message = "postId는 1 이상 이어야 합니다.") @PathVariable Long postId, @RequestHeader(value = "Authorization", required = false) String authorizationHeader) { Long userId = (authorizationHeader == null) ? null : tokenProviderService.getUserIdFromToken(authorizationHeader); - CommnuityPost post = communityPostQueryService.getPostDetail(postId); - SelectCategory category = categoryService.findByEntityIdAndType(post.getId(), post.getType()); - return BaseResponse.onSuccess(communityPostConverter.toPostDetailDTO(post, userId, category)); + return BaseResponse.onSuccess(communityPostQueryService.getPostDetail(userId, postId)); } @GetMapping("/preivew") @@ -111,8 +109,7 @@ public BaseResponse getPostPreivewL @Min(value = 0, message = "page는 0 이상 이어야 합니다.") @RequestParam(defaultValue = "0") int page, @Min(value = 1, message = "size는 1 이상 이어야 합니다.") @RequestParam(defaultValue = "10") int size) { - Slice postSlice = communityPostQueryService.getPostList(keyword, lastPopularityScore, lastPostId, lastLikeCnt, lastHit, postType, category, sortType, filter, page, size); - return BaseResponse.onSuccess(communityPostConverter.toPostPreviewListDTO(postSlice.getContent(), postSlice.hasNext())); + return BaseResponse.onSuccess(communityPostQueryService.getPostList(keyword, lastPopularityScore, lastPostId, lastLikeCnt, lastHit, postType, category, sortType, filter, page, size)); } @PostMapping("/{postId}/comments") From ccc15451c211a916633e10810d3abaafeb588696 Mon Sep 17 00:00:00 2001 From: strongmhk Date: Mon, 30 Sep 2024 09:33:05 +0900 Subject: [PATCH 4/8] =?UTF-8?q?:bug:=20[#148]=20fix:=20Bean=20=EC=88=9C?= =?UTF-8?q?=ED=99=98=20=EC=B0=B8=EC=A1=B0=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/service/CommunityPostQueryServiceImpl.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/gaji/service/domain/post/service/CommunityPostQueryServiceImpl.java b/src/main/java/gaji/service/domain/post/service/CommunityPostQueryServiceImpl.java index 38d53318..66f80aa0 100644 --- a/src/main/java/gaji/service/domain/post/service/CommunityPostQueryServiceImpl.java +++ b/src/main/java/gaji/service/domain/post/service/CommunityPostQueryServiceImpl.java @@ -37,9 +37,7 @@ public class CommunityPostQueryServiceImpl implements CommunityPostQueryService private final HashtagService hashtagService; private final CommunityPostBookMarkService postBookMarkService; private final CommunityPostLikesService postLikesService; - private final CommunityPostQueryService communityPostQueryService; - private final CommunityPostConverter communityPostConverter; @Override @@ -97,7 +95,7 @@ public CommunityPostResponseDTO.PostDetailDTO getPostDetail(Long userId, Long po boolean isBookmarked = (userId == null) ? false : postBookMarkService.existsByUserAndPost(userId, findPost); boolean isLiked = (userId == null) ? false : postLikesService.existsByUserAndPost(userId, findPost); - boolean isWriter = (userId == null) ? false : communityPostQueryService.isPostWriter(userId, findPost); + boolean isWriter = (userId == null) ? false : isPostWriter(userId, findPost); SelectCategory category = categoryService.findByEntityIdAndType(findPost.getId(), findPost.getType()); From e1f39ab30d4f4be62a234f5921497fd25210634e Mon Sep 17 00:00:00 2001 From: strongmhk Date: Mon, 30 Sep 2024 09:55:32 +0900 Subject: [PATCH 5/8] =?UTF-8?q?:truck:=20[#148]=20rename:=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/web/controller/CommunityPostRestController.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 7b28144f..5236eec5 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 @@ -1,13 +1,11 @@ package gaji.service.domain.post.web.controller; -import gaji.service.domain.common.entity.SelectCategory; import gaji.service.domain.common.service.CategoryService; import gaji.service.domain.enums.PostStatusEnum; import gaji.service.domain.enums.PostTypeEnum; import gaji.service.domain.enums.SortType; import gaji.service.domain.post.converter.CommunityCommentConverter; import gaji.service.domain.post.converter.CommunityPostConverter; -import gaji.service.domain.post.entity.CommnuityPost; import gaji.service.domain.post.entity.CommunityComment; import gaji.service.domain.post.entity.PostBookmark; import gaji.service.domain.post.entity.PostLikes; @@ -97,7 +95,7 @@ public BaseResponse getPostDetail(@Min(v @Parameter(name = "sortType", description = "정렬 유형(hot, recent, like, hit)"), @Parameter(name = "filter", description = "게시글의 상태(모집중, 모집완료, 미완료질문, 해결완료)"), }) - public BaseResponse getPostPreivewList(@RequestParam(required = false) String keyword, + public BaseResponse getPostPreviewList(@RequestParam(required = false) String keyword, @Min(value = 0, message = "lastPopularityScore는 0 이상 이어야 합니다.") @RequestParam(required = false) Integer lastPopularityScore, @Min(value = 1, message = "lastPostId는 1 이상 이어야 합니다.") @RequestParam(required = false) Long lastPostId, @Min(value = 0, message = "lastLikeCnt는 0 이상 이어야 합니다.") @RequestParam(required = false) Integer lastLikeCnt, From a787acf494fae06eb013d9657e2e67800b9d9f87 Mon Sep 17 00:00:00 2001 From: strongmhk Date: Mon, 30 Sep 2024 11:05:08 +0900 Subject: [PATCH 6/8] =?UTF-8?q?:recycle:=20[#148]=20refactor:=20CommunityC?= =?UTF-8?q?omment=20=EA=B4=80=EB=A0=A8=20API=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/service/CommunityCommentService.java | 3 ++- .../service/CommunityCommentServiceImpl.java | 22 +++++++++++++++++-- .../service/CommunityPostCommandService.java | 7 +++--- .../CommunityPostCommandServiceImpl.java | 14 +++++++----- .../CommunityPostQueryServiceImpl.java | 5 +---- .../CommunityPostRestController.java | 19 +++++----------- 6 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/main/java/gaji/service/domain/post/service/CommunityCommentService.java b/src/main/java/gaji/service/domain/post/service/CommunityCommentService.java index 3f357c77..2d3ac6b1 100644 --- a/src/main/java/gaji/service/domain/post/service/CommunityCommentService.java +++ b/src/main/java/gaji/service/domain/post/service/CommunityCommentService.java @@ -2,6 +2,7 @@ import gaji.service.domain.post.entity.CommnuityPost; import gaji.service.domain.post.entity.CommunityComment; +import gaji.service.domain.post.web.dto.CommunityPostCommentResponseDTO; import gaji.service.domain.post.web.dto.CommunityPostRequestDTO; import gaji.service.domain.user.entity.User; import org.springframework.data.domain.Slice; @@ -13,7 +14,7 @@ public interface CommunityCommentService { CommunityComment createCommentByCheckParentCommentIdIsNull(Long parentCommentId, CommunityPostRequestDTO.WriteCommentRequestDTO request, User findUser, CommnuityPost findPost); void hardDeleteComment(CommunityComment comment); CommunityComment findByCommentId(Long commentId); - Slice getCommentListByPost(Long postId, Integer lastGroupNum, int page, int size); + CommunityPostCommentResponseDTO.PostCommentListDTO getCommentListByPost(Long userId, Long postId, Integer lastGroupNum, int page, int size); boolean isCommentWriter(Long userId, CommunityComment comment); void validCommentWriter(Long userId, CommunityComment comment); diff --git a/src/main/java/gaji/service/domain/post/service/CommunityCommentServiceImpl.java b/src/main/java/gaji/service/domain/post/service/CommunityCommentServiceImpl.java index 9fe9c7c1..9399ba62 100644 --- a/src/main/java/gaji/service/domain/post/service/CommunityCommentServiceImpl.java +++ b/src/main/java/gaji/service/domain/post/service/CommunityCommentServiceImpl.java @@ -1,11 +1,14 @@ package gaji.service.domain.post.service; import gaji.service.domain.post.code.CommunityCommentErrorStatus; +import gaji.service.domain.post.converter.CommunityCommentConverter; import gaji.service.domain.post.converter.CommunityPostConverter; import gaji.service.domain.post.entity.CommnuityPost; import gaji.service.domain.post.entity.CommunityComment; import gaji.service.domain.post.repository.CommunityCommentJpaRepository; +import gaji.service.domain.post.web.dto.CommunityPostCommentResponseDTO; import gaji.service.domain.post.web.dto.CommunityPostRequestDTO; +import gaji.service.domain.post.web.dto.CommunityPostResponseDTO; import gaji.service.domain.user.entity.User; import gaji.service.global.exception.RestApiException; import lombok.RequiredArgsConstructor; @@ -14,6 +17,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.List; + @Service @RequiredArgsConstructor @Transactional(readOnly = true) @@ -45,10 +51,22 @@ public void hardDeleteComment(CommunityComment comment) { } @Override - public Slice getCommentListByPost(Long postId, Integer lastGroupNum, int page, int size) { + public CommunityPostCommentResponseDTO.PostCommentListDTO getCommentListByPost(Long userId, Long postId, Integer lastGroupNum, int page, int size) { PageRequest pageRequest = PageRequest.of(page, size); CommnuityPost findPost = communityPostQueryService.findPostByPostId(postId); - return communityCommentJpaRepository.findBySliceAndPostFetchJoinWithUser(lastGroupNum, findPost, pageRequest); + Slice commentSlice = communityCommentJpaRepository.findBySliceAndPostFetchJoinWithUser(lastGroupNum, findPost, pageRequest); + + List postCommentDTOList = new ArrayList<>(); + + for (CommunityComment communityComment : commentSlice.getContent()) { + boolean isWriter = (userId == null) ? false : isCommentWriter(userId, communityComment); + postCommentDTOList.add(CommunityCommentConverter.toPostCommentDTO(communityComment, isWriter)); + } + + return CommunityPostCommentResponseDTO.PostCommentListDTO.builder() + .commentList(postCommentDTOList) + .hasNext(commentSlice.hasNext()) + .build(); } @Override 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 357cf6cf..4b6da6b8 100644 --- a/src/main/java/gaji/service/domain/post/service/CommunityPostCommandService.java +++ b/src/main/java/gaji/service/domain/post/service/CommunityPostCommandService.java @@ -4,6 +4,7 @@ import gaji.service.domain.post.entity.CommunityComment; import gaji.service.domain.post.entity.PostBookmark; import gaji.service.domain.post.entity.PostLikes; +import gaji.service.domain.post.web.dto.CommunityPostCommentResponseDTO; import gaji.service.domain.post.web.dto.CommunityPostRequestDTO; import gaji.service.domain.post.web.dto.CommunityPostResponseDTO; @@ -11,12 +12,12 @@ public interface CommunityPostCommandService { CommunityPostResponseDTO.PostIdResponseDTO uploadPost(Long userId, CommunityPostRequestDTO.UploadPostRequestDTO request); CommunityPostResponseDTO.PostIdResponseDTO editPost(Long userId, Long postId, CommunityPostRequestDTO.EditPostRequestDTO request); - CommunityComment writeCommentOnCommunityPost(Long userId, Long postId, Long parentCommentId, CommunityPostRequestDTO.WriteCommentRequestDTO request); + CommunityPostCommentResponseDTO.WriteCommentResponseDTO writeCommentOnCommunityPost(Long userId, Long postId, Long parentCommentId, CommunityPostRequestDTO.WriteCommentRequestDTO request); void hardDeleteComment(Long userId, Long commentId); void hardDeleteCommunityPost(Long userId, Long postId); - PostBookmark bookmarkCommunityPost(Long userId, Long postId); + CommunityPostResponseDTO.PostBookmarkIdDTO bookmarkCommunityPost(Long userId, Long postId); void cancelbookmarkCommunityPost(Long userId, Long postId); - PostLikes likeCommunityPost(Long userId, Long postId); + CommunityPostResponseDTO.PostLikesIdDTO likeCommunityPost(Long userId, Long postId); void cancelLikeCommunityPost(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 76878e39..6ac88a24 100644 --- a/src/main/java/gaji/service/domain/post/service/CommunityPostCommandServiceImpl.java +++ b/src/main/java/gaji/service/domain/post/service/CommunityPostCommandServiceImpl.java @@ -10,6 +10,7 @@ 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.CommunityCommentConverter; import gaji.service.domain.post.converter.CommunityPostConverter; import gaji.service.domain.post.entity.CommnuityPost; import gaji.service.domain.post.entity.CommunityComment; @@ -18,6 +19,7 @@ import gaji.service.domain.post.repository.CommunityPostBookmarkRepository; import gaji.service.domain.post.repository.CommunityPostJpaRepository; import gaji.service.domain.post.repository.CommunityPostLikesRepository; +import gaji.service.domain.post.web.dto.CommunityPostCommentResponseDTO; import gaji.service.domain.post.web.dto.CommunityPostRequestDTO; import gaji.service.domain.post.web.dto.CommunityPostResponseDTO; import gaji.service.domain.user.entity.User; @@ -86,7 +88,7 @@ public CommunityPostResponseDTO.PostIdResponseDTO editPost(Long userId, Long pos } @Override - public CommunityComment writeCommentOnCommunityPost(Long userId, Long postId, Long parentCommentId, CommunityPostRequestDTO.WriteCommentRequestDTO request) { + public CommunityPostCommentResponseDTO.WriteCommentResponseDTO writeCommentOnCommunityPost(Long userId, Long postId, Long parentCommentId, CommunityPostRequestDTO.WriteCommentRequestDTO request) { User findUser = userQueryService.findUserById(userId); CommnuityPost findPost = communityPostQueryService.findPostByPostId(postId); @@ -97,7 +99,7 @@ public CommunityComment writeCommentOnCommunityPost(Long userId, Long postId, Lo // 게시글의 댓글 수 증가 newComment.getPost().increaseCommentCnt(); - return newComment; + return CommunityCommentConverter.toWriteCommentResponseDTO(newComment); } @Override @@ -128,7 +130,7 @@ public void hardDeleteCommunityPost(Long userId, Long postId) { } @Override - public PostBookmark bookmarkCommunityPost(Long userId, Long postId) { + public CommunityPostResponseDTO.PostBookmarkIdDTO bookmarkCommunityPost(Long userId, Long postId) { User findUser = userQueryService.findUserById(userId); CommnuityPost findPost = communityPostQueryService.findPostByPostId(postId); @@ -140,7 +142,7 @@ public PostBookmark bookmarkCommunityPost(Long userId, Long postId) { // 게시글 북마크 수 증가 newPostBookmark.getPost().increaseBookmarkCnt(); - return newPostBookmark; + return CommunityPostConverter.toPostBookmarkIdDTO(newPostBookmark); } @Override @@ -159,7 +161,7 @@ public void cancelbookmarkCommunityPost(Long userId, Long postId) { } @Override - public PostLikes likeCommunityPost(Long userId, Long postId) { + public CommunityPostResponseDTO.PostLikesIdDTO likeCommunityPost(Long userId, Long postId) { User findUser = userQueryService.findUserById(userId); CommnuityPost findPost = communityPostQueryService.findPostByPostId(postId); @@ -172,7 +174,7 @@ public PostLikes likeCommunityPost(Long userId, Long postId) { // 좋아요 수, 인기점수 증가 findPost.increaseLikeCnt(); findPost.increasePopularityScoreByLike(); - return newPostLikes; + return CommunityPostConverter.toPostLikesIdDTO(newPostLikes); } @Override diff --git a/src/main/java/gaji/service/domain/post/service/CommunityPostQueryServiceImpl.java b/src/main/java/gaji/service/domain/post/service/CommunityPostQueryServiceImpl.java index 66f80aa0..dee965f4 100644 --- a/src/main/java/gaji/service/domain/post/service/CommunityPostQueryServiceImpl.java +++ b/src/main/java/gaji/service/domain/post/service/CommunityPostQueryServiceImpl.java @@ -83,7 +83,6 @@ public CommunityPostResponseDTO.PostPreviewListDTO getPostList(String keyword, .postList(postPreviewDTOList) .hasNext(postSlice.hasNext()) .build(); -// return CommunityPostConverter.toPostPreviewListDTO(postSlice.getContent(), postSlice.hasNext(), selectHashtagList); } @Override @@ -101,11 +100,9 @@ public CommunityPostResponseDTO.PostDetailDTO getPostDetail(Long userId, Long po List selectHashtagList = hashtagService.findAllFetchJoinWithHashtagByEntityIdAndPostType(findPost.getId(), findPost.getType()); - CommunityPostResponseDTO.PostDetailDTO postDetailDTO = CommunityPostConverter.toPostDetailDTO(findPost, category, selectHashtagList, isBookmarked, isLiked, isWriter); - findPost.increaseHitCnt(); findPost.increasePopularityScoreByHit(); - return postDetailDTO; + return CommunityPostConverter.toPostDetailDTO(findPost, category, selectHashtagList, isBookmarked, isLiked, isWriter); } @Override 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 5236eec5..c5fb247a 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 @@ -7,8 +7,6 @@ import gaji.service.domain.post.converter.CommunityCommentConverter; import gaji.service.domain.post.converter.CommunityPostConverter; import gaji.service.domain.post.entity.CommunityComment; -import gaji.service.domain.post.entity.PostBookmark; -import gaji.service.domain.post.entity.PostLikes; import gaji.service.domain.post.service.CommunityCommentService; import gaji.service.domain.post.service.CommunityPostCommandService; import gaji.service.domain.post.service.CommunityPostQueryService; @@ -36,7 +34,6 @@ public class CommunityPostRestController { private final CommunityPostQueryService communityPostQueryService; private final CommunityCommentService commentService; private final TokenProviderService tokenProviderService; - private final CommunityPostConverter communityPostConverter; private final CommunityCommentConverter communityCommentConverter; private final CategoryService categoryService; @@ -121,8 +118,7 @@ public BaseResponse wri @Min(value = 1, message = "parentCommentId는 1 이상 이어야 합니다.") @RequestParam(required = false) Long parentCommentId, @RequestBody @Valid CommunityPostRequestDTO.WriteCommentRequestDTO request) { Long userId = tokenProviderService.getUserIdFromToken(authorizationHeader); - CommunityComment newComment = communityPostCommandService.writeCommentOnCommunityPost(userId, postId, parentCommentId, request); - return BaseResponse.onSuccess(CommunityCommentConverter.toWriteCommentResponseDTO(newComment)); + return BaseResponse.onSuccess(communityPostCommandService.writeCommentOnCommunityPost(userId, postId, parentCommentId, request)); } @DeleteMapping("/comments/{commentId}") @@ -145,10 +141,8 @@ public BaseResponse getComme @Min(value = 0, message = "page는 0 이상 이어야 합니다.") @RequestParam(defaultValue = "0") int page, @Min(value = 1, message = "size는 1 이상 이어야 합니다.") @RequestParam(defaultValue = "10") int size) // 페이지 크기 (기본값 10)) { - Long userId = tokenProviderService.getUserIdFromToken(authorizationHeader); - Slice commentSlice = commentService.getCommentListByPost(postId, lastGroupNum, page, size); - CommunityPostCommentResponseDTO.PostCommentListDTO postCommentDTOList = communityCommentConverter.toPostCommentListDTO(commentSlice.getContent(), commentSlice.hasNext(), userId); - return BaseResponse.onSuccess(postCommentDTOList); + Long userId = (authorizationHeader == null) ? null : tokenProviderService.getUserIdFromToken(authorizationHeader); + return BaseResponse.onSuccess(commentService.getCommentListByPost(userId, postId, lastGroupNum, page, size)); } @PostMapping("/{postId}/bookmarks") @@ -159,9 +153,7 @@ public BaseResponse getComme public BaseResponse bookmarkCommunityPost(@RequestHeader("Authorization") String authorizationHeader, @Min(value = 1, message = "postId는 1 이상 이어야 합니다.") @PathVariable Long postId) { Long userId = tokenProviderService.getUserIdFromToken(authorizationHeader); - PostBookmark newPostBookmark = communityPostCommandService.bookmarkCommunityPost(userId, postId); - - return BaseResponse.onSuccess(CommunityPostConverter.toPostBookmarkIdDTO(newPostBookmark)); + return BaseResponse.onSuccess(communityPostCommandService.bookmarkCommunityPost(userId, postId)); } @DeleteMapping("/{postId}/bookmarks") @@ -184,8 +176,7 @@ public BaseResponse cancelBookmarkCommunityPost(@RequestHeader("Authorization") public BaseResponse likeCommunityPost(@RequestHeader("Authorization") String authorizationHeader, @Min(value = 1, message = "postId는 1 이상 이어야 합니다.") @PathVariable Long postId) { Long userId = tokenProviderService.getUserIdFromToken(authorizationHeader); - PostLikes newPostLikes = communityPostCommandService.likeCommunityPost(userId, postId); - return BaseResponse.onSuccess(CommunityPostConverter.toPostLikesIdDTO(newPostLikes)); + return BaseResponse.onSuccess(communityPostCommandService.likeCommunityPost(userId, postId)); } @DeleteMapping("/{postId}/likes") From 6875001f391baf78e8fb33ab492b87bbe4ad0deb Mon Sep 17 00:00:00 2001 From: strongmhk Date: Fri, 4 Oct 2024 10:21:02 +0900 Subject: [PATCH 7/8] =?UTF-8?q?:sparkles:=20[#148]=20feature:=20github=20i?= =?UTF-8?q?ssue=20=EC=83=9D=EC=84=B1=EC=8B=9C=20jira=20=EC=9D=B4=EC=8A=88?= =?UTF-8?q?=20=EC=9E=90=EB=8F=99=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/issue-form.yml | 48 +++++++++++++++++ .github/workflows/create-jira-issue.yml | 70 +++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/issue-form.yml create mode 100644 .github/workflows/create-jira-issue.yml diff --git a/.github/ISSUE_TEMPLATE/issue-form.yml b/.github/ISSUE_TEMPLATE/issue-form.yml new file mode 100644 index 00000000..59d7969c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/issue-form.yml @@ -0,0 +1,48 @@ +name: 'GAJI-Server 이슈 생성' +description: 'GAJI-Server Repo에 이슈를 생성하며, 생성된 이슈는 Jira와 연동됩니다.' +labels: [order] +title: '[LABEL] 이슈 이름을 작성해주세요' +body: + - type: input + id: parentKey + attributes: + label: '상위 작업 Ticket Number' + description: '상위 작업의 Ticket Number를 기입해주세요' + placeholder: 'GAJI-00' + validations: + required: true + - type: input + id: description + attributes: + label: '이슈 내용(Description)' + description: '이슈에 대해서 간략히 설명해주세요' + validations: + required: true + - type: textarea + id: details + attributes: + label: '상세 내용(Details)' + description: '이슈에 대해서 자세히 설명해주세요' + value: | + - About Details + validations: + required: true + - type: textarea + id: tasks + attributes: + label: '체크리스트(Tasks)' + description: '해당 이슈에 대해 필요한 작업목록을 작성해주세요' + value: | + - [ ] Task1 + - [ ] Task2 + validations: + required: true + - type: textarea + id: references + attributes: + label: '참조(References)' + description: '해당 이슈과 관련된 레퍼런스를 참조해주세요' + value: | + - Reference1 + validations: + required: false \ No newline at end of file diff --git a/.github/workflows/create-jira-issue.yml b/.github/workflows/create-jira-issue.yml new file mode 100644 index 00000000..428df24c --- /dev/null +++ b/.github/workflows/create-jira-issue.yml @@ -0,0 +1,70 @@ +name: Create Jira issue +on: + issues: + types: + - opened +jobs: + create-issue: + name: Create Jira issue + runs-on: ubuntu-latest + steps: + - name: Login + uses: atlassian/gajira-login@v3 + env: + JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} + JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} + JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} + - name: Checkout develop code + uses: actions/checkout@v4 + with: + ref: develop + - name: Issue Parser + uses: stefanbuck/github-issue-praser@v3 + id: issue-parser + with: + template-path: ./.github/ISSUE_TEMPLATE/issue-form.yml + - name: Log Issue Parser + run: | + echo '${{ steps.issue-parser.outputs.jsonString }}' + - name: Convert markdown to Jira Syntax + uses: peter-evans/jira2md@v1 + id: md2jira + with: + input-text: | + ### Github Issue Link + - ${{ github.event.issue.html_url }} + + ${{ github.event.issue.body }} + mode: md2jira + - name: Create Issue + id: create + uses: atlassian/gajira-create@v3 + with: + project: GAJI + issuetype: 하위 작업 + summary: '${{ github.event.issue.title }}' + description: '${{ steps.md2jira.outputs.output-text }}' + fields: | + { + "parent": { + "key": "${{ steps.issue-parser.outputs.issueparser_parentKey }}" + } + } + - name: Log created issue + run: echo "Jira Issue ${{ steps.issue-parser.outputs.parentKey }}/${{ steps.create.outputs.issue }} was created" + - name: Checkout develop code + uses: actions/checkout@v4 + with: + ref: develop + - name: Create branch with Ticket number + run: | + sanitized_branch_name=$(echo '${{ github.event.issue.title }}/${{ steps.create.outputs.issue }}' | sed 's/[^a-zA-Z0-9_/-]/-/g') + sanitized_branch_name=$(echo "$sanitized_branch_name" | sed 's/-\+/-/g' | sed 's/-$//g' | sed 's/^-\+//g') + git checkout -b "$sanitized_branch_name" + git push origin "$sanitized_branch_name" + - name: Update issue title + uses: actions-cool/issues-helper@v3 + with: + actions: 'update-issue' + token: ${{ secrets.GITHUB_TOKEN }} + title: '${{ steps.create.outputs.issue }} ${{ github.event.issue.title }}' \ No newline at end of file From 1a8987ec2917301ccef9e2b3565757e4e9545423 Mon Sep 17 00:00:00 2001 From: strongmhk Date: Wed, 4 Dec 2024 15:21:54 +0900 Subject: [PATCH 8/8] =?UTF-8?q?=F0=9F=94=A8=20[#148]=20fix:=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F?= =?UTF-8?q?=20=EC=9D=91=EB=8B=B5=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/converter/CommunityCommentConverter.java | 2 +- .../domain/post/service/CommunityPostCommandServiceImpl.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/gaji/service/domain/post/converter/CommunityCommentConverter.java b/src/main/java/gaji/service/domain/post/converter/CommunityCommentConverter.java index e430265f..0b0016c2 100644 --- a/src/main/java/gaji/service/domain/post/converter/CommunityCommentConverter.java +++ b/src/main/java/gaji/service/domain/post/converter/CommunityCommentConverter.java @@ -26,7 +26,7 @@ public static CommunityPostCommentResponseDTO.PostCommentDTO toPostCommentDTO(Co return CommunityPostCommentResponseDTO.PostCommentDTO.builder() .commentId(comment.getId()) .userId(comment.getUser().getId()) - .userNickName(comment.getUser().getName()) + .userNickName(comment.getUser().getNickname()) .commentBody(comment.getBody()) .groupNum(comment.getGroupNum()) .depth(comment.getDepth()) 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 6ac88a24..3fc2c0e0 100644 --- a/src/main/java/gaji/service/domain/post/service/CommunityPostCommandServiceImpl.java +++ b/src/main/java/gaji/service/domain/post/service/CommunityPostCommandServiceImpl.java @@ -182,8 +182,7 @@ public void cancelLikeCommunityPost(Long userId, Long postId) { User findUser = userQueryService.findUserById(userId); CommnuityPost findPost = communityPostQueryService.findPostByPostId(postId); - // 검증 - communityPostQueryService.validPostWriter(findUser.getId(), findPost); + // TODO: like owner인지 검증 // 삭제 postLikesRepository.deleteByUserAndPost(findUser, findPost);