From c3af6dd4d99058a5d3a29ac6431de462929044a6 Mon Sep 17 00:00:00 2001 From: letskuku Date: Sat, 23 Mar 2024 23:58:21 +0900 Subject: [PATCH 01/13] =?UTF-8?q?#147=20chore:=20getPost=20TODO=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EB=B0=8F=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EC=84=A4=EB=AA=85=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/application/PostServiceImpl.java | 17 ++++++++--------- .../post/presentation/PostController.java | 5 +++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java b/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java index bc7935b1..08e77b8b 100644 --- a/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java +++ b/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java @@ -81,7 +81,7 @@ public PostGetResponse getPost(Long postId, Long customerId) { if (customerId != 0) { customerService.getCustomerByCustomerId(customerId); } - post.checkReadAuthority(customerId); // TODO: 비공개 상담에 답변 단 판매자도 볼 수 있게 해야함 + post.checkReadAuthority(customerId); return PostGetResponse.of(post); } @@ -104,19 +104,11 @@ public List getRandomPosts() { @Override public PostGetResponse getCounselorPostContent(Long postId, Long customerId) { - Post post = checkAndGetCounselorPost(postId, customerId); return PostGetResponse.of(post); } - private Post getProceedingPost(Long postId) { - Post post = getPostByPostId(postId); - - post.checkPostProceeding(); - return post; - } - @Override public Post checkAndGetCounselorPost(Long postId, Long customerId) { if (checkCounselorReadAuthority(postId, customerId)) @@ -133,4 +125,11 @@ private Boolean checkCounselorReadAuthority(Long postId, Long customerId){ return comment != null; } + + private Post getProceedingPost(Long postId) { + Post post = getPostByPostId(postId); + + post.checkPostProceeding(); + return post; + } } diff --git a/src/main/java/com/example/sharemind/post/presentation/PostController.java b/src/main/java/com/example/sharemind/post/presentation/PostController.java index bd22f828..d96f5481 100644 --- a/src/main/java/com/example/sharemind/post/presentation/PostController.java +++ b/src/main/java/com/example/sharemind/post/presentation/PostController.java @@ -93,8 +93,9 @@ public ResponseEntity getIsSaved(@PathVariable Long post return ResponseEntity.ok(postService.getIsSaved(postId)); } - @Operation(summary = "일대다 상담 질문 단건 조회", - description = "- 일대다 상담 질문 단건 조회\n - 로그인한 사용자일 경우 헤더에 accessToken을 넣어주세요") + @Operation(summary = "구매자&비로그인 사용자 일대다 상담 질문 단건 조회", description = """ + - 구매자&비로그인 사용자 일대다 상담 질문 단건 조회 + - 로그인한 사용자일 경우 헤더에 accessToken을 넣어주세요""") @ApiResponses({ @ApiResponse(responseCode = "200", description = "조회 성공"), @ApiResponse(responseCode = "403", description = "접근 권한이 없는 상담(다른 회원의 비공개 상담 접근 시도)", From 936f704dfa5d105ead37f5019f5325d11618e77b Mon Sep 17 00:00:00 2001 From: letskuku Date: Sun, 24 Mar 2024 00:22:06 +0900 Subject: [PATCH 02/13] =?UTF-8?q?#147=20feat:=20=EC=9D=BC=EB=8C=80?= =?UTF-8?q?=EB=8B=A4=20=EC=A7=88=EB=AC=B8=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=99=80=20=EB=8B=A8=EA=B1=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20dto=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/PostGetListResponse.java | 74 +++++++++++++++++++ .../post/dto/response/PostGetResponse.java | 27 ++----- 2 files changed, 81 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/example/sharemind/post/dto/response/PostGetListResponse.java diff --git a/src/main/java/com/example/sharemind/post/dto/response/PostGetListResponse.java b/src/main/java/com/example/sharemind/post/dto/response/PostGetListResponse.java new file mode 100644 index 00000000..0e7f7209 --- /dev/null +++ b/src/main/java/com/example/sharemind/post/dto/response/PostGetListResponse.java @@ -0,0 +1,74 @@ +package com.example.sharemind.post.dto.response; + +import com.example.sharemind.global.utils.TimeUtil; +import com.example.sharemind.post.domain.Post; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; +import lombok.Getter; + +@Getter +public class PostGetListResponse { + + @Schema(description = "일대다 질문 아이디") + private final Long postId; + + @Schema(description = "제목") + private final String title; + + @Schema(description = "상담 내용") + private final String content; + + @Schema(description = "공개/비공개 여부") + private final Boolean isPublic; + + @Schema(description = "좋아요 수") + private final Long totalLike; + + @Schema(description = "스크랩 수") + private final Long totalScrap; + + @Schema(description = "답변 수") + private final Long totalComment; + + @Schema(description = "마지막 업데이트 일시", example = "8분 전") + private final String updatedAt; + + @Builder + public PostGetListResponse(Long postId, String title, String content, Boolean isPublic, + Long totalLike, Long totalScrap, Long totalComment, String updatedAt) { + this.postId = postId; + this.title = title; + this.content = content; + this.isPublic = isPublic; + this.totalLike = totalLike; + this.totalScrap = totalScrap; + this.totalComment = totalComment; + this.updatedAt = updatedAt; + } + + public static PostGetListResponse of(Post post) { + return PostGetListResponse.builder() + .postId(post.getPostId()) + .title(post.getTitle()) + .content(post.getContent()) + .isPublic(post.getIsPublic()) + .totalLike(post.getTotalLike()) + .totalScrap(post.getTotalScrap()) + .totalComment(post.getTotalComment()) + .updatedAt(TimeUtil.getUpdatedAt(post.getUpdatedAt())) + .build(); + } + + public static PostGetListResponse ofIsNotCompleted(Post post) { + return PostGetListResponse.builder() + .postId(post.getPostId()) + .title(null) + .content(null) + .isPublic(post.getIsPublic()) + .totalLike(post.getTotalLike()) + .totalScrap(post.getTotalScrap()) + .totalComment(post.getTotalComment()) + .updatedAt(TimeUtil.getUpdatedAt(post.getUpdatedAt())) + .build(); + } +} diff --git a/src/main/java/com/example/sharemind/post/dto/response/PostGetResponse.java b/src/main/java/com/example/sharemind/post/dto/response/PostGetResponse.java index 15191b50..0adb1668 100644 --- a/src/main/java/com/example/sharemind/post/dto/response/PostGetResponse.java +++ b/src/main/java/com/example/sharemind/post/dto/response/PostGetResponse.java @@ -12,6 +12,9 @@ public class PostGetResponse { @Schema(description = "일대다 질문 아이디") private final Long postId; + @Schema(description = "상담 카테고리", example = "권태기") + private final String consultCategory; + @Schema(description = "제목") private final String title; @@ -27,47 +30,31 @@ public class PostGetResponse { @Schema(description = "스크랩 수") private final Long totalScrap; - @Schema(description = "답변 수") - private final Long totalComment; - @Schema(description = "마지막 업데이트 일시", example = "8분 전") private final String updatedAt; @Builder - public PostGetResponse(Long postId, String title, String content, Boolean isPublic, - Long totalLike, Long totalScrap, Long totalComment, String updatedAt) { + public PostGetResponse(Long postId, String consultCategory, String title, String content, + Boolean isPublic, Long totalLike, Long totalScrap, String updatedAt) { this.postId = postId; + this.consultCategory = consultCategory; this.title = title; this.content = content; this.isPublic = isPublic; this.totalLike = totalLike; this.totalScrap = totalScrap; - this.totalComment = totalComment; this.updatedAt = updatedAt; } public static PostGetResponse of(Post post) { return PostGetResponse.builder() .postId(post.getPostId()) + .consultCategory(post.getConsultCategory().getDisplayName()) .title(post.getTitle()) .content(post.getContent()) .isPublic(post.getIsPublic()) .totalLike(post.getTotalLike()) .totalScrap(post.getTotalScrap()) - .totalComment(post.getTotalComment()) - .updatedAt(TimeUtil.getUpdatedAt(post.getUpdatedAt())) - .build(); - } - - public static PostGetResponse ofIsNotCompleted(Post post) { - return PostGetResponse.builder() - .postId(post.getPostId()) - .title(null) - .content(null) - .isPublic(post.getIsPublic()) - .totalLike(post.getTotalLike()) - .totalScrap(post.getTotalScrap()) - .totalComment(post.getTotalComment()) .updatedAt(TimeUtil.getUpdatedAt(post.getUpdatedAt())) .build(); } From d1dd839f3c4819f00f7bb7c465535fbcf27bffda Mon Sep 17 00:00:00 2001 From: letskuku Date: Sun, 24 Mar 2024 00:22:26 +0900 Subject: [PATCH 03/13] =?UTF-8?q?#147=20feat:=20=EC=9D=BC=EB=8C=80?= =?UTF-8?q?=EB=8B=A4=20=EC=A7=88=EB=AC=B8=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=99=80=20=EB=8B=A8=EA=B1=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20dto=20=EB=B6=84=EB=A6=AC=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/sharemind/post/application/PostService.java | 3 ++- .../example/sharemind/post/application/PostServiceImpl.java | 5 +++-- .../example/sharemind/post/presentation/PostController.java | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/sharemind/post/application/PostService.java b/src/main/java/com/example/sharemind/post/application/PostService.java index 27d3ccb1..263c89d1 100644 --- a/src/main/java/com/example/sharemind/post/application/PostService.java +++ b/src/main/java/com/example/sharemind/post/application/PostService.java @@ -4,6 +4,7 @@ import com.example.sharemind.post.dto.request.PostCreateRequest; import com.example.sharemind.post.dto.request.PostUpdateRequest; import com.example.sharemind.post.dto.response.PostGetIsSavedResponse; +import com.example.sharemind.post.dto.response.PostGetListResponse; import com.example.sharemind.post.dto.response.PostGetResponse; import java.util.List; @@ -21,7 +22,7 @@ public interface PostService { PostGetResponse getPost(Long postId, Long customerId); - List getPostsByCustomer(Boolean filter, Long postId, Long customerId); + List getPostsByCustomer(Boolean filter, Long postId, Long customerId); List getRandomPosts(); diff --git a/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java b/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java index 08e77b8b..e5ecb8f6 100644 --- a/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java +++ b/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java @@ -11,6 +11,7 @@ import com.example.sharemind.post.dto.request.PostCreateRequest; import com.example.sharemind.post.dto.request.PostUpdateRequest; import com.example.sharemind.post.dto.response.PostGetIsSavedResponse; +import com.example.sharemind.post.dto.response.PostGetListResponse; import com.example.sharemind.post.dto.response.PostGetResponse; import com.example.sharemind.post.exception.PostErrorCode; import com.example.sharemind.post.exception.PostException; @@ -87,13 +88,13 @@ public PostGetResponse getPost(Long postId, Long customerId) { } @Override - public List getPostsByCustomer(Boolean filter, Long postId, Long customerId) { + public List getPostsByCustomer(Boolean filter, Long postId, Long customerId) { Customer customer = customerService.getCustomerByCustomerId(customerId); return postRepository.findAllByCustomerAndIsActivatedIsTrue(customer, filter, postId, POST_CUSTOMER_PAGE_SIZE).stream() .map(post -> (post.getIsCompleted() != null && !post.getIsCompleted()) - ? PostGetResponse.ofIsNotCompleted(post) : PostGetResponse.of(post)) + ? PostGetListResponse.ofIsNotCompleted(post) : PostGetListResponse.of(post)) .toList(); } diff --git a/src/main/java/com/example/sharemind/post/presentation/PostController.java b/src/main/java/com/example/sharemind/post/presentation/PostController.java index d96f5481..5f2bee98 100644 --- a/src/main/java/com/example/sharemind/post/presentation/PostController.java +++ b/src/main/java/com/example/sharemind/post/presentation/PostController.java @@ -6,6 +6,7 @@ import com.example.sharemind.post.dto.request.PostCreateRequest; import com.example.sharemind.post.dto.request.PostUpdateRequest; import com.example.sharemind.post.dto.response.PostGetIsSavedResponse; +import com.example.sharemind.post.dto.response.PostGetListResponse; import com.example.sharemind.post.dto.response.PostGetResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -135,7 +136,7 @@ public ResponseEntity getPost(@PathVariable Long postId, 2. 2번째 요청부터 postId는 직전 요청의 조회 결과 4개 중 마지막 postId""") }) @GetMapping("/customers") - public ResponseEntity> getPostsByCustomer(@RequestParam Boolean filter, + public ResponseEntity> getPostsByCustomer(@RequestParam Boolean filter, @RequestParam Long postId, @AuthenticationPrincipal CustomUserDetails customUserDetails) { return ResponseEntity.ok(postService.getPostsByCustomer(filter, postId, From 06788dd635c2f9fe539b7d3bb4f1ebe99f7eb88b Mon Sep 17 00:00:00 2001 From: letskuku Date: Sun, 24 Mar 2024 02:20:28 +0900 Subject: [PATCH 04/13] =?UTF-8?q?#147=20feat:=20=EC=9D=BC=EB=8C=80?= =?UTF-8?q?=EB=8B=A4=20=EC=83=81=EB=8B=B4=20=EC=A7=88=EB=AC=B8=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=EB=84=A4=EC=9D=B4=EC=85=98=EC=9D=84=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=ED=95=84=EB=93=9C=20dto=EC=97=90=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 --- .../post/dto/response/PostGetListResponse.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/sharemind/post/dto/response/PostGetListResponse.java b/src/main/java/com/example/sharemind/post/dto/response/PostGetListResponse.java index 0e7f7209..d7d74d92 100644 --- a/src/main/java/com/example/sharemind/post/dto/response/PostGetListResponse.java +++ b/src/main/java/com/example/sharemind/post/dto/response/PostGetListResponse.java @@ -2,7 +2,9 @@ import com.example.sharemind.global.utils.TimeUtil; import com.example.sharemind.post.domain.Post; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.v3.oas.annotations.media.Schema; +import java.time.LocalDateTime; import lombok.Builder; import lombok.Getter; @@ -33,9 +35,14 @@ public class PostGetListResponse { @Schema(description = "마지막 업데이트 일시", example = "8분 전") private final String updatedAt; + @Schema(description = "페이지네이션 위한 업데이트 일시") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss", timezone = "Asia/Seoul") + private final LocalDateTime updatedAtForPaging; + @Builder public PostGetListResponse(Long postId, String title, String content, Boolean isPublic, - Long totalLike, Long totalScrap, Long totalComment, String updatedAt) { + Long totalLike, Long totalScrap, Long totalComment, String updatedAt, + LocalDateTime updatedAtForPaging) { this.postId = postId; this.title = title; this.content = content; @@ -44,6 +51,7 @@ public PostGetListResponse(Long postId, String title, String content, Boolean is this.totalScrap = totalScrap; this.totalComment = totalComment; this.updatedAt = updatedAt; + this.updatedAtForPaging = updatedAtForPaging; } public static PostGetListResponse of(Post post) { @@ -56,6 +64,7 @@ public static PostGetListResponse of(Post post) { .totalScrap(post.getTotalScrap()) .totalComment(post.getTotalComment()) .updatedAt(TimeUtil.getUpdatedAt(post.getUpdatedAt())) + .updatedAtForPaging(post.getUpdatedAt()) .build(); } @@ -69,6 +78,7 @@ public static PostGetListResponse ofIsNotCompleted(Post post) { .totalScrap(post.getTotalScrap()) .totalComment(post.getTotalComment()) .updatedAt(TimeUtil.getUpdatedAt(post.getUpdatedAt())) + .updatedAtForPaging(post.getUpdatedAt()) .build(); } } From 6ba23ecf0586abff807e8ca8da58e75de9c5ae97 Mon Sep 17 00:00:00 2001 From: letskuku Date: Sun, 24 Mar 2024 02:21:03 +0900 Subject: [PATCH 05/13] =?UTF-8?q?#147=20feat:=20=EC=9D=BC=EB=8C=80?= =?UTF-8?q?=EB=8B=A4=20=EC=83=81=EB=8B=B4=20=EA=B3=B5=EA=B0=9C=20=EC=A7=88?= =?UTF-8?q?=EB=AC=B8=20=ED=8E=98=EC=9D=B4=EC=A7=80=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EC=85=98=EC=9D=84=20=EC=9C=84=ED=95=9C=20queryDsl=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/repository/PostCustomRepository.java | 4 ++++ .../repository/PostCustomRepositoryImpl.java | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main/java/com/example/sharemind/post/repository/PostCustomRepository.java b/src/main/java/com/example/sharemind/post/repository/PostCustomRepository.java index 93b64f4f..662fdf68 100644 --- a/src/main/java/com/example/sharemind/post/repository/PostCustomRepository.java +++ b/src/main/java/com/example/sharemind/post/repository/PostCustomRepository.java @@ -2,10 +2,14 @@ import com.example.sharemind.customer.domain.Customer; import com.example.sharemind.post.domain.Post; +import java.time.LocalDateTime; import java.util.List; public interface PostCustomRepository { List findAllByCustomerAndIsActivatedIsTrue(Customer customer, Boolean filter, Long postId, int size); + + List findAllByIsPublicAndIsActivatedIsTrue(Long postId, LocalDateTime updatedAt, + int size); } diff --git a/src/main/java/com/example/sharemind/post/repository/PostCustomRepositoryImpl.java b/src/main/java/com/example/sharemind/post/repository/PostCustomRepositoryImpl.java index 1fb7a4ad..fe275d75 100644 --- a/src/main/java/com/example/sharemind/post/repository/PostCustomRepositoryImpl.java +++ b/src/main/java/com/example/sharemind/post/repository/PostCustomRepositoryImpl.java @@ -6,6 +6,7 @@ import com.example.sharemind.post.domain.QPost; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; +import java.time.LocalDateTime; import java.util.List; import lombok.RequiredArgsConstructor; @@ -29,6 +30,19 @@ public List findAllByCustomerAndIsActivatedIsTrue(Customer customer, Boole ).orderBy(post.postId.desc()).limit(size).fetch(); } + @Override + public List findAllByIsPublicAndIsActivatedIsTrue(Long postId, LocalDateTime updatedAt, + int size) { + return jpaQueryFactory + .selectFrom(post) + .where( + post.isPublic.isTrue(), + post.postStatus.eq(PostStatus.COMPLETED), + post.isActivated.isTrue(), + lessThanUpdatedAtAndPostId(postId, updatedAt) + ).orderBy(post.updatedAt.desc(), post.postId.desc()).limit(size).fetch(); + } + private BooleanExpression postStatusIn(Boolean filter) { return filter ? post.postStatus.in(PostStatus.WAITING, PostStatus.PROCEEDING, PostStatus.REPORTED) : null; @@ -37,4 +51,9 @@ private BooleanExpression postStatusIn(Boolean filter) { private BooleanExpression lessThanPostId(Long postId) { return postId != 0 ? post.postId.lt(postId) : null; } + + private BooleanExpression lessThanUpdatedAtAndPostId(Long postId, LocalDateTime updatedAt) { + return postId != 0 ? post.updatedAt.lt(updatedAt) + .or(post.updatedAt.eq(updatedAt).and(post.postId.lt(postId))) : null; + } } From 0aad04f1af19a349122adecfab9e6d6873772aec Mon Sep 17 00:00:00 2001 From: letskuku Date: Sun, 24 Mar 2024 02:21:59 +0900 Subject: [PATCH 06/13] =?UTF-8?q?#147=20feat:=20=EC=9D=BC=EB=8C=80?= =?UTF-8?q?=EB=8B=A4=20=EC=83=81=EB=8B=B4=20=EA=B3=B5=EA=B0=9C=20=EC=A7=88?= =?UTF-8?q?=EB=AC=B8=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/application/PostService.java | 3 +++ .../post/application/PostServiceImpl.java | 22 +++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/sharemind/post/application/PostService.java b/src/main/java/com/example/sharemind/post/application/PostService.java index 263c89d1..2f99235b 100644 --- a/src/main/java/com/example/sharemind/post/application/PostService.java +++ b/src/main/java/com/example/sharemind/post/application/PostService.java @@ -6,6 +6,7 @@ import com.example.sharemind.post.dto.response.PostGetIsSavedResponse; import com.example.sharemind.post.dto.response.PostGetListResponse; import com.example.sharemind.post.dto.response.PostGetResponse; +import java.time.LocalDateTime; import java.util.List; public interface PostService { @@ -24,6 +25,8 @@ public interface PostService { List getPostsByCustomer(Boolean filter, Long postId, Long customerId); + List getPublicPostsByCustomer(Long postId, LocalDateTime updatedAt); + List getRandomPosts(); PostGetResponse getCounselorPostContent(Long postId, Long customerId); diff --git a/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java b/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java index e5ecb8f6..90eda094 100644 --- a/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java +++ b/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java @@ -16,6 +16,7 @@ import com.example.sharemind.post.exception.PostErrorCode; import com.example.sharemind.post.exception.PostException; import com.example.sharemind.post.repository.PostRepository; +import java.time.LocalDateTime; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -88,7 +89,8 @@ public PostGetResponse getPost(Long postId, Long customerId) { } @Override - public List getPostsByCustomer(Boolean filter, Long postId, Long customerId) { + public List getPostsByCustomer(Boolean filter, Long postId, + Long customerId) { Customer customer = customerService.getCustomerByCustomerId(customerId); return postRepository.findAllByCustomerAndIsActivatedIsTrue(customer, filter, postId, @@ -98,6 +100,15 @@ public List getPostsByCustomer(Boolean filter, Long postId, .toList(); } + @Override + public List getPublicPostsByCustomer(Long postId, + LocalDateTime updatedAt) { + return postRepository.findAllByIsPublicAndIsActivatedIsTrue(postId, updatedAt, + POST_CUSTOMER_PAGE_SIZE).stream() + .map(PostGetListResponse::of) + .toList(); + } + @Override public List getRandomPosts() { return postRepository.findRandomProceedingPostIds(); @@ -112,17 +123,20 @@ public PostGetResponse getCounselorPostContent(Long postId, Long customerId) { @Override public Post checkAndGetCounselorPost(Long postId, Long customerId) { - if (checkCounselorReadAuthority(postId, customerId)) + if (checkCounselorReadAuthority(postId, customerId)) { return getPostByPostId(postId); + } + return getProceedingPost(postId); } - private Boolean checkCounselorReadAuthority(Long postId, Long customerId){ + private Boolean checkCounselorReadAuthority(Long postId, Long customerId) { Post post = getPostByPostId(postId); Counselor counselor = counselorService.getCounselorByCustomerId(customerId); - Comment comment = commentRepository.findByPostAndCounselorAndIsActivatedIsTrue(post, counselor); + Comment comment = commentRepository.findByPostAndCounselorAndIsActivatedIsTrue(post, + counselor); return comment != null; } From f323772a1cfe9e300d7bd9ea5c28d5d29afe509e Mon Sep 17 00:00:00 2001 From: letskuku Date: Sun, 24 Mar 2024 02:23:34 +0900 Subject: [PATCH 07/13] =?UTF-8?q?#147=20feat:=20=EA=B5=AC=EB=A7=A4?= =?UTF-8?q?=EC=9E=90=20=EC=82=AC=EC=9D=B4=EB=93=9C=20=EC=9D=BC=EB=8C=80?= =?UTF-8?q?=EB=8B=A4=20=EC=83=81=EB=8B=B4=20=EA=B3=B5=EA=B0=9C=EC=83=81?= =?UTF-8?q?=EB=8B=B4=20=ED=83=AD=20=EC=83=81=EB=8B=B4=20=EB=AA=A9=EB=A1=9D?= =?UTF-8?q?=20=EA=B8=B0=EB=B3=B8=EC=88=9C=20=EC=A1=B0=ED=9A=8C=20api=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/presentation/PostController.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/sharemind/post/presentation/PostController.java b/src/main/java/com/example/sharemind/post/presentation/PostController.java index 5f2bee98..8eaf25d5 100644 --- a/src/main/java/com/example/sharemind/post/presentation/PostController.java +++ b/src/main/java/com/example/sharemind/post/presentation/PostController.java @@ -17,8 +17,10 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import java.time.LocalDateTime; import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; @@ -136,13 +138,37 @@ public ResponseEntity getPost(@PathVariable Long postId, 2. 2번째 요청부터 postId는 직전 요청의 조회 결과 4개 중 마지막 postId""") }) @GetMapping("/customers") - public ResponseEntity> getPostsByCustomer(@RequestParam Boolean filter, + public ResponseEntity> getPostsByCustomer( + @RequestParam Boolean filter, @RequestParam Long postId, @AuthenticationPrincipal CustomUserDetails customUserDetails) { return ResponseEntity.ok(postService.getPostsByCustomer(filter, postId, customUserDetails.getCustomer().getCustomerId())); } + @Operation(summary = "구매자 사이드 공개상담 탭 일대다 상담 리스트 기본순 조회", description = """ + - 구매자 사이드의 공개상담 탭에서 답변 완료된 일대다 상담 질문 리스트 기본순 조회 + - 주소 형식: /api/v1/posts/customers/public?postId=0&updatedAt=2024-03-22T00:47:59""") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "조회 성공") + }) + @Parameters({ + @Parameter(name = "postId", description = """ + - 조회 결과는 4개씩 반환하며, postId와 updatedAt으로 구분 + 1. 최초 조회 요청이면 postId는 0 + 2. 2번째 요청부터 postId는 직전 요청의 조회 결과 4개 중 마지막 postId"""), + @Parameter(name = "updatedAt", description = """ + 1. 최초 조회 요청이면 지금 시간 + 2. 2번째 요청부터 updatedAt 직전 요청의 조회 결과 4개 중 마지막 updatedAtForPaging + 3. 형식 예시에 적어둔 것과 꼭 맞춰주셔야 합니다"""), + }) + @GetMapping("/customers/public") + public ResponseEntity> getPublicPostsByCustomer( + @RequestParam Long postId, + @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") LocalDateTime updatedAt) { + return ResponseEntity.ok(postService.getPublicPostsByCustomer(postId, updatedAt)); + } + @Operation(summary = "상담사 랜덤 일대다 상담 ID 리스트 반환", description = """ - 상담사 일대다 상담 답변을 위한 진행중인 상담 ID 리스트를 랜덤으로 50개 반환하는 API - 없을 경우 빈 리스트를 반환 @@ -171,7 +197,8 @@ public ResponseEntity> getRandomPosts() { }) @GetMapping("/counselors/{postId}") public ResponseEntity getPostInfo(@PathVariable Long postId, - @AuthenticationPrincipal CustomUserDetails customUserDetails) { - return ResponseEntity.ok(postService.getCounselorPostContent(postId, customUserDetails.getCustomer().getCustomerId())); + @AuthenticationPrincipal CustomUserDetails customUserDetails) { + return ResponseEntity.ok(postService.getCounselorPostContent(postId, + customUserDetails.getCustomer().getCustomerId())); } } From 2162eda47f3aefd01a2cf2275ba8cfcf2cbc9320 Mon Sep 17 00:00:00 2001 From: letskuku Date: Sun, 24 Mar 2024 02:23:55 +0900 Subject: [PATCH 08/13] =?UTF-8?q?#147=20chore:=20=EA=B5=AC=EB=A7=A4?= =?UTF-8?q?=EC=9E=90=20=EC=82=AC=EC=9D=B4=EB=93=9C=20=EC=9D=BC=EB=8C=80?= =?UTF-8?q?=EB=8B=A4=20=EC=83=81=EB=8B=B4=20=EA=B3=B5=EA=B0=9C=EC=83=81?= =?UTF-8?q?=EB=8B=B4=20=ED=83=AD=20=EC=83=81=EB=8B=B4=20=EB=AA=A9=EB=A1=9D?= =?UTF-8?q?=20=EA=B8=B0=EB=B3=B8=EC=88=9C=20=EC=A1=B0=ED=9A=8C=20api=20?= =?UTF-8?q?=EA=B6=8C=ED=95=9C=20=ED=95=B4=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/sharemind/global/config/SecurityConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/example/sharemind/global/config/SecurityConfig.java b/src/main/java/com/example/sharemind/global/config/SecurityConfig.java index 55ab3de7..2e9d9520 100644 --- a/src/main/java/com/example/sharemind/global/config/SecurityConfig.java +++ b/src/main/java/com/example/sharemind/global/config/SecurityConfig.java @@ -56,6 +56,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .requestMatchers("/index.html", "/favicon.ico", "/chat/**", "/customer.html", "/counselor.html").permitAll() .requestMatchers(HttpMethod.GET, "/api/v1/posts/{postId}").permitAll() + .requestMatchers(HttpMethod.GET, "/api/v1/posts/customers/public/**").permitAll() .requestMatchers("/api/v1/admins/**").hasRole(ROLE_ADMIN) .requestMatchers("/api/v1/letters/counselors/**", "/api/v1/reviews/counselors**").hasRole(ROLE_COUNSELOR) .requestMatchers("/api/v1/chats/counselors/**").hasRole(ROLE_COUNSELOR) From c475d27b9344b251e1031e90e3f18b10af955a47 Mon Sep 17 00:00:00 2001 From: letskuku Date: Sun, 24 Mar 2024 03:00:18 +0900 Subject: [PATCH 09/13] =?UTF-8?q?#147=20feat:=20=EA=B3=84=EC=B8=B5?= =?UTF-8?q?=EA=B0=84=20=EC=9D=B8=EA=B8=B0=EC=88=9C=20=EC=9D=BC=EB=8C=80?= =?UTF-8?q?=EB=8B=A4=20=EC=83=81=EB=8B=B4=20=EC=A0=95=EB=B3=B4=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99=20=EC=9C=84=ED=95=9C=20dto=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/PostGetPopularityResponse.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/com/example/sharemind/post/dto/response/PostGetPopularityResponse.java diff --git a/src/main/java/com/example/sharemind/post/dto/response/PostGetPopularityResponse.java b/src/main/java/com/example/sharemind/post/dto/response/PostGetPopularityResponse.java new file mode 100644 index 00000000..0514f8c6 --- /dev/null +++ b/src/main/java/com/example/sharemind/post/dto/response/PostGetPopularityResponse.java @@ -0,0 +1,29 @@ +package com.example.sharemind.post.dto.response; + +import com.example.sharemind.post.domain.Post; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; +import lombok.Getter; + +@Getter +public class PostGetPopularityResponse { + + @Schema(description = "일대다 질문 아이디") + private final Long postId; + + @Schema(description = "제목") + private final String title; + + @Builder + public PostGetPopularityResponse(Long postId, String title) { + this.postId = postId; + this.title = title; + } + + public static PostGetPopularityResponse of(Post post) { + return PostGetPopularityResponse.builder() + .postId(post.getPostId()) + .title(post.getTitle()) + .build(); + } +} From f86c8348fb5e87da966ed69599ad00c675294060 Mon Sep 17 00:00:00 2001 From: letskuku Date: Sun, 24 Mar 2024 03:00:59 +0900 Subject: [PATCH 10/13] =?UTF-8?q?#147=20feat:=20=EC=9D=BC=EB=8C=80?= =?UTF-8?q?=EB=8B=A4=20=EC=83=81=EB=8B=B4=20=EC=9D=B8=EA=B8=B0=EC=88=9C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20=EB=B9=84=EC=A6=88?= =?UTF-8?q?=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sharemind/post/application/PostService.java | 3 +++ .../sharemind/post/application/PostServiceImpl.java | 13 ++++++++++++- .../sharemind/post/repository/PostRepository.java | 11 ++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/sharemind/post/application/PostService.java b/src/main/java/com/example/sharemind/post/application/PostService.java index 2f99235b..1b41b68f 100644 --- a/src/main/java/com/example/sharemind/post/application/PostService.java +++ b/src/main/java/com/example/sharemind/post/application/PostService.java @@ -5,6 +5,7 @@ import com.example.sharemind.post.dto.request.PostUpdateRequest; import com.example.sharemind.post.dto.response.PostGetIsSavedResponse; import com.example.sharemind.post.dto.response.PostGetListResponse; +import com.example.sharemind.post.dto.response.PostGetPopularityResponse; import com.example.sharemind.post.dto.response.PostGetResponse; import java.time.LocalDateTime; import java.util.List; @@ -27,6 +28,8 @@ public interface PostService { List getPublicPostsByCustomer(Long postId, LocalDateTime updatedAt); + List getPopularityPosts(); + List getRandomPosts(); PostGetResponse getCounselorPostContent(Long postId, Long customerId); diff --git a/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java b/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java index 90eda094..f03cb24a 100644 --- a/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java +++ b/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java @@ -12,10 +12,12 @@ import com.example.sharemind.post.dto.request.PostUpdateRequest; import com.example.sharemind.post.dto.response.PostGetIsSavedResponse; import com.example.sharemind.post.dto.response.PostGetListResponse; +import com.example.sharemind.post.dto.response.PostGetPopularityResponse; import com.example.sharemind.post.dto.response.PostGetResponse; import com.example.sharemind.post.exception.PostErrorCode; import com.example.sharemind.post.exception.PostException; import com.example.sharemind.post.repository.PostRepository; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; import lombok.RequiredArgsConstructor; @@ -28,6 +30,7 @@ public class PostServiceImpl implements PostService { private static final int POST_CUSTOMER_PAGE_SIZE = 4; + private static final int POST_POPULARITY_SIZE = 3; private final CustomerService customerService; private final CounselorService counselorService; @@ -104,11 +107,19 @@ public List getPostsByCustomer(Boolean filter, Long postId, public List getPublicPostsByCustomer(Long postId, LocalDateTime updatedAt) { return postRepository.findAllByIsPublicAndIsActivatedIsTrue(postId, updatedAt, - POST_CUSTOMER_PAGE_SIZE).stream() + POST_CUSTOMER_PAGE_SIZE).stream() .map(PostGetListResponse::of) .toList(); } + @Override + public List getPopularityPosts() { + return postRepository.findPopularityPosts(LocalDate.now().minusWeeks(1), + POST_POPULARITY_SIZE).stream() + .map(PostGetPopularityResponse::of) + .toList(); + } + @Override public List getRandomPosts() { return postRepository.findRandomProceedingPostIds(); diff --git a/src/main/java/com/example/sharemind/post/repository/PostRepository.java b/src/main/java/com/example/sharemind/post/repository/PostRepository.java index d851a2f7..2459e378 100644 --- a/src/main/java/com/example/sharemind/post/repository/PostRepository.java +++ b/src/main/java/com/example/sharemind/post/repository/PostRepository.java @@ -1,6 +1,7 @@ package com.example.sharemind.post.repository; import com.example.sharemind.post.domain.Post; +import java.time.LocalDate; import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; @@ -14,6 +15,14 @@ public interface PostRepository extends JpaRepository, PostCustomRep List findAllByIsPaidIsFalseAndIsActivatedIsTrue(); - @Query(value = "SELECT post_id FROM post WHERE post_status = 'PROCEEDING' ORDER BY RAND() LIMIT 50", nativeQuery = true) + @Query(value = "SELECT * FROM post " + + "WHERE is_public = true AND post_status = 'COMPLETED' AND is_activated = true " + + "AND updated_at >= :weekAgo " + + "ORDER BY total_like DESC LIMIT :size", nativeQuery = true) + List findPopularityPosts(LocalDate weekAgo, int size); + + @Query(value = "SELECT post_id FROM post " + + "WHERE post_status = 'PROCEEDING' " + + "ORDER BY RAND() LIMIT 50", nativeQuery = true) List findRandomProceedingPostIds(); } From 5a8b119a2ba0e84987fe09f363cce66afc6dc561 Mon Sep 17 00:00:00 2001 From: letskuku Date: Sun, 24 Mar 2024 03:01:10 +0900 Subject: [PATCH 11/13] =?UTF-8?q?#147=20feat:=20=EC=9D=BC=EB=8C=80?= =?UTF-8?q?=EB=8B=A4=20=EC=83=81=EB=8B=B4=20=EC=9D=B8=EA=B8=B0=EC=88=9C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sharemind/post/presentation/PostController.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/example/sharemind/post/presentation/PostController.java b/src/main/java/com/example/sharemind/post/presentation/PostController.java index 8eaf25d5..fd5b90f8 100644 --- a/src/main/java/com/example/sharemind/post/presentation/PostController.java +++ b/src/main/java/com/example/sharemind/post/presentation/PostController.java @@ -7,6 +7,7 @@ import com.example.sharemind.post.dto.request.PostUpdateRequest; import com.example.sharemind.post.dto.response.PostGetIsSavedResponse; import com.example.sharemind.post.dto.response.PostGetListResponse; +import com.example.sharemind.post.dto.response.PostGetPopularityResponse; import com.example.sharemind.post.dto.response.PostGetResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -169,6 +170,16 @@ public ResponseEntity> getPublicPostsByCustomer( return ResponseEntity.ok(postService.getPublicPostsByCustomer(postId, updatedAt)); } + @Operation(summary = "구매자 사이드 공개상담 탭 일대다 상담 리스트 인기순 조회", description = """ + - 구매자 사이드의 공개상담 탭에서 답변 완료된 일대다 상담 질문 리스트 인기순 조회""") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "조회 성공") + }) + @GetMapping("/customers/public/likes") + public ResponseEntity> getPopularityPosts() { + return ResponseEntity.ok(postService.getPopularityPosts()); + } + @Operation(summary = "상담사 랜덤 일대다 상담 ID 리스트 반환", description = """ - 상담사 일대다 상담 답변을 위한 진행중인 상담 ID 리스트를 랜덤으로 50개 반환하는 API - 없을 경우 빈 리스트를 반환 From e24574421a154ea5f2260ec19c6484d4c80ffbc8 Mon Sep 17 00:00:00 2001 From: letskuku Date: Sun, 24 Mar 2024 19:59:11 +0900 Subject: [PATCH 12/13] =?UTF-8?q?#147=20feat:=20=EC=9D=BC=EB=8C=80?= =?UTF-8?q?=EB=8B=A4=20=EC=83=81=EB=8B=B4=20=EA=B8=B0=EB=B3=B8=EC=88=9C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EB=A5=BC=20=EC=9C=84=ED=95=B4=20Post?= =?UTF-8?q?=EC=97=90=20=EB=8B=B5=EB=B3=80=20=EC=99=84=EB=A3=8C=20=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=ED=95=84=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/com/example/sharemind/post/domain/Post.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/example/sharemind/post/domain/Post.java b/src/main/java/com/example/sharemind/post/domain/Post.java index 196358d6..b765fe9a 100644 --- a/src/main/java/com/example/sharemind/post/domain/Post.java +++ b/src/main/java/com/example/sharemind/post/domain/Post.java @@ -17,6 +17,7 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.validation.constraints.Size; +import java.time.LocalDateTime; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -71,6 +72,9 @@ public class Post extends BaseEntity { @Column(name = "is_completed") private Boolean isCompleted; + @Column(name = "finished_at") + private LocalDateTime finishedAt; + @Builder public Post(Customer customer, Long cost, Boolean isPublic) { this.customer = customer; @@ -89,6 +93,10 @@ public void updateIsPaid() { public void updatePostStatus(PostStatus postStatus) { this.postStatus = postStatus; + + if (this.postStatus == PostStatus.COMPLETED) { + this.finishedAt = LocalDateTime.now(); + } } public void updatePost(ConsultCategory consultCategory, String title, String content, From 9456d054b936ddb214c8814052070e7b27112b6f Mon Sep 17 00:00:00 2001 From: letskuku Date: Sun, 24 Mar 2024 20:00:35 +0900 Subject: [PATCH 13/13] =?UTF-8?q?#147=20feat:=20=EB=8B=B5=EB=B3=80=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C=20=EC=8B=9C=EA=B0=84=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sharemind/post/application/PostService.java | 2 +- .../sharemind/post/application/PostServiceImpl.java | 4 ++-- .../post/dto/response/PostGetListResponse.java | 12 ++++++------ .../sharemind/post/presentation/PostController.java | 12 ++++++------ .../post/repository/PostCustomRepository.java | 2 +- .../post/repository/PostCustomRepositoryImpl.java | 12 ++++++------ 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/example/sharemind/post/application/PostService.java b/src/main/java/com/example/sharemind/post/application/PostService.java index 1b41b68f..430aa901 100644 --- a/src/main/java/com/example/sharemind/post/application/PostService.java +++ b/src/main/java/com/example/sharemind/post/application/PostService.java @@ -26,7 +26,7 @@ public interface PostService { List getPostsByCustomer(Boolean filter, Long postId, Long customerId); - List getPublicPostsByCustomer(Long postId, LocalDateTime updatedAt); + List getPublicPostsByCustomer(Long postId, LocalDateTime finishedAt); List getPopularityPosts(); diff --git a/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java b/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java index f03cb24a..c935cbf9 100644 --- a/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java +++ b/src/main/java/com/example/sharemind/post/application/PostServiceImpl.java @@ -105,8 +105,8 @@ public List getPostsByCustomer(Boolean filter, Long postId, @Override public List getPublicPostsByCustomer(Long postId, - LocalDateTime updatedAt) { - return postRepository.findAllByIsPublicAndIsActivatedIsTrue(postId, updatedAt, + LocalDateTime finishedAt) { + return postRepository.findAllByIsPublicAndIsActivatedIsTrue(postId, finishedAt, POST_CUSTOMER_PAGE_SIZE).stream() .map(PostGetListResponse::of) .toList(); diff --git a/src/main/java/com/example/sharemind/post/dto/response/PostGetListResponse.java b/src/main/java/com/example/sharemind/post/dto/response/PostGetListResponse.java index d7d74d92..620c21d2 100644 --- a/src/main/java/com/example/sharemind/post/dto/response/PostGetListResponse.java +++ b/src/main/java/com/example/sharemind/post/dto/response/PostGetListResponse.java @@ -35,14 +35,14 @@ public class PostGetListResponse { @Schema(description = "마지막 업데이트 일시", example = "8분 전") private final String updatedAt; - @Schema(description = "페이지네이션 위한 업데이트 일시") + @Schema(description = "답변 완료 일시") @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss", timezone = "Asia/Seoul") - private final LocalDateTime updatedAtForPaging; + private final LocalDateTime finishedAt; @Builder public PostGetListResponse(Long postId, String title, String content, Boolean isPublic, Long totalLike, Long totalScrap, Long totalComment, String updatedAt, - LocalDateTime updatedAtForPaging) { + LocalDateTime finishedAt) { this.postId = postId; this.title = title; this.content = content; @@ -51,7 +51,7 @@ public PostGetListResponse(Long postId, String title, String content, Boolean is this.totalScrap = totalScrap; this.totalComment = totalComment; this.updatedAt = updatedAt; - this.updatedAtForPaging = updatedAtForPaging; + this.finishedAt = finishedAt; } public static PostGetListResponse of(Post post) { @@ -64,7 +64,7 @@ public static PostGetListResponse of(Post post) { .totalScrap(post.getTotalScrap()) .totalComment(post.getTotalComment()) .updatedAt(TimeUtil.getUpdatedAt(post.getUpdatedAt())) - .updatedAtForPaging(post.getUpdatedAt()) + .finishedAt(post.getFinishedAt()) .build(); } @@ -78,7 +78,7 @@ public static PostGetListResponse ofIsNotCompleted(Post post) { .totalScrap(post.getTotalScrap()) .totalComment(post.getTotalComment()) .updatedAt(TimeUtil.getUpdatedAt(post.getUpdatedAt())) - .updatedAtForPaging(post.getUpdatedAt()) + .finishedAt(post.getFinishedAt()) .build(); } } diff --git a/src/main/java/com/example/sharemind/post/presentation/PostController.java b/src/main/java/com/example/sharemind/post/presentation/PostController.java index fd5b90f8..6aac1180 100644 --- a/src/main/java/com/example/sharemind/post/presentation/PostController.java +++ b/src/main/java/com/example/sharemind/post/presentation/PostController.java @@ -149,25 +149,25 @@ public ResponseEntity> getPostsByCustomer( @Operation(summary = "구매자 사이드 공개상담 탭 일대다 상담 리스트 기본순 조회", description = """ - 구매자 사이드의 공개상담 탭에서 답변 완료된 일대다 상담 질문 리스트 기본순 조회 - - 주소 형식: /api/v1/posts/customers/public?postId=0&updatedAt=2024-03-22T00:47:59""") + - 주소 형식: /api/v1/posts/customers/public?postId=0&finishedAt=2024-03-22T00:47:59""") @ApiResponses({ @ApiResponse(responseCode = "200", description = "조회 성공") }) @Parameters({ @Parameter(name = "postId", description = """ - - 조회 결과는 4개씩 반환하며, postId와 updatedAt으로 구분 + - 조회 결과는 4개씩 반환하며, postId와 finishedAt으로 구분 1. 최초 조회 요청이면 postId는 0 2. 2번째 요청부터 postId는 직전 요청의 조회 결과 4개 중 마지막 postId"""), - @Parameter(name = "updatedAt", description = """ + @Parameter(name = "finishedAt", description = """ 1. 최초 조회 요청이면 지금 시간 - 2. 2번째 요청부터 updatedAt 직전 요청의 조회 결과 4개 중 마지막 updatedAtForPaging + 2. 2번째 요청부터 finishedAt 직전 요청의 조회 결과 4개 중 마지막 finishedAt 3. 형식 예시에 적어둔 것과 꼭 맞춰주셔야 합니다"""), }) @GetMapping("/customers/public") public ResponseEntity> getPublicPostsByCustomer( @RequestParam Long postId, - @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") LocalDateTime updatedAt) { - return ResponseEntity.ok(postService.getPublicPostsByCustomer(postId, updatedAt)); + @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") LocalDateTime finishedAt) { + return ResponseEntity.ok(postService.getPublicPostsByCustomer(postId, finishedAt)); } @Operation(summary = "구매자 사이드 공개상담 탭 일대다 상담 리스트 인기순 조회", description = """ diff --git a/src/main/java/com/example/sharemind/post/repository/PostCustomRepository.java b/src/main/java/com/example/sharemind/post/repository/PostCustomRepository.java index 662fdf68..5e76b558 100644 --- a/src/main/java/com/example/sharemind/post/repository/PostCustomRepository.java +++ b/src/main/java/com/example/sharemind/post/repository/PostCustomRepository.java @@ -10,6 +10,6 @@ public interface PostCustomRepository { List findAllByCustomerAndIsActivatedIsTrue(Customer customer, Boolean filter, Long postId, int size); - List findAllByIsPublicAndIsActivatedIsTrue(Long postId, LocalDateTime updatedAt, + List findAllByIsPublicAndIsActivatedIsTrue(Long postId, LocalDateTime finishedAt, int size); } diff --git a/src/main/java/com/example/sharemind/post/repository/PostCustomRepositoryImpl.java b/src/main/java/com/example/sharemind/post/repository/PostCustomRepositoryImpl.java index fe275d75..ff940e35 100644 --- a/src/main/java/com/example/sharemind/post/repository/PostCustomRepositoryImpl.java +++ b/src/main/java/com/example/sharemind/post/repository/PostCustomRepositoryImpl.java @@ -31,7 +31,7 @@ public List findAllByCustomerAndIsActivatedIsTrue(Customer customer, Boole } @Override - public List findAllByIsPublicAndIsActivatedIsTrue(Long postId, LocalDateTime updatedAt, + public List findAllByIsPublicAndIsActivatedIsTrue(Long postId, LocalDateTime finishedAt, int size) { return jpaQueryFactory .selectFrom(post) @@ -39,8 +39,8 @@ public List findAllByIsPublicAndIsActivatedIsTrue(Long postId, LocalDateTi post.isPublic.isTrue(), post.postStatus.eq(PostStatus.COMPLETED), post.isActivated.isTrue(), - lessThanUpdatedAtAndPostId(postId, updatedAt) - ).orderBy(post.updatedAt.desc(), post.postId.desc()).limit(size).fetch(); + lessThanFinishedAtAndPostId(postId, finishedAt) + ).orderBy(post.finishedAt.desc(), post.postId.desc()).limit(size).fetch(); } private BooleanExpression postStatusIn(Boolean filter) { @@ -52,8 +52,8 @@ private BooleanExpression lessThanPostId(Long postId) { return postId != 0 ? post.postId.lt(postId) : null; } - private BooleanExpression lessThanUpdatedAtAndPostId(Long postId, LocalDateTime updatedAt) { - return postId != 0 ? post.updatedAt.lt(updatedAt) - .or(post.updatedAt.eq(updatedAt).and(post.postId.lt(postId))) : null; + private BooleanExpression lessThanFinishedAtAndPostId(Long postId, LocalDateTime finishedAt) { + return postId != 0 ? post.finishedAt.lt(finishedAt) + .or(post.finishedAt.eq(finishedAt).and(post.postId.lt(postId))) : null; } }