From d0c79260e531ca83d18756e17a1a66496c2e6400 Mon Sep 17 00:00:00 2001 From: feel-coding Date: Sat, 24 Feb 2024 16:48:31 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=ED=8C=94=EB=A1=9C=EC=9A=B0?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EC=82=AC=EC=9A=A9=EC=9E=90=EC=9D=98=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=AA=A9=EB=A1=9D=EB=A7=8C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=B6=94=EA=B0=80=20#11?= =?UTF-8?q?8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cvsgo/dto/review/ReadReviewRequestDto.java | 5 ++++- .../com/cvsgo/repository/UserFollowRepository.java | 3 +++ src/main/java/com/cvsgo/service/ReviewService.java | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cvsgo/dto/review/ReadReviewRequestDto.java b/src/main/java/com/cvsgo/dto/review/ReadReviewRequestDto.java index ad52d589..08885044 100644 --- a/src/main/java/com/cvsgo/dto/review/ReadReviewRequestDto.java +++ b/src/main/java/com/cvsgo/dto/review/ReadReviewRequestDto.java @@ -14,11 +14,14 @@ public class ReadReviewRequestDto { private final List ratings; + private final Boolean followingOnly; + public ReadReviewRequestDto(ReviewSortBy sortBy, List categoryIds, List tagIds, - List ratings) { + List ratings, Boolean followingOnly) { this.sortBy = sortBy; this.categoryIds = categoryIds; this.tagIds = tagIds; this.ratings = ratings; + this.followingOnly = followingOnly != null && followingOnly; } } diff --git a/src/main/java/com/cvsgo/repository/UserFollowRepository.java b/src/main/java/com/cvsgo/repository/UserFollowRepository.java index 78140188..db4d0cb3 100644 --- a/src/main/java/com/cvsgo/repository/UserFollowRepository.java +++ b/src/main/java/com/cvsgo/repository/UserFollowRepository.java @@ -2,6 +2,7 @@ import com.cvsgo.entity.User; import com.cvsgo.entity.UserFollow; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; @@ -11,4 +12,6 @@ public interface UserFollowRepository extends JpaRepository { Optional findByUserAndFollower(User user, User follower); + List findAllByFollower(User follower); + } diff --git a/src/main/java/com/cvsgo/service/ReviewService.java b/src/main/java/com/cvsgo/service/ReviewService.java index 3207da42..a3654331 100644 --- a/src/main/java/com/cvsgo/service/ReviewService.java +++ b/src/main/java/com/cvsgo/service/ReviewService.java @@ -35,6 +35,7 @@ import com.cvsgo.repository.ReviewImageRepository; import com.cvsgo.repository.ReviewLikeRepository; import com.cvsgo.repository.ReviewRepository; +import com.cvsgo.repository.UserFollowRepository; import com.cvsgo.repository.UserRepository; import com.cvsgo.repository.UserTagRepository; import jakarta.persistence.EntityManager; @@ -68,6 +69,8 @@ public class ReviewService { private final UserRepository userRepository; + private final UserFollowRepository userFollowRepository; + /** * 리뷰를 추가합니다. * @@ -161,6 +164,13 @@ public ReadReviewResponseDto readReviewList(User user, ReadReviewRequestDto requ getUserTags(reviewDto.getReviewerId(), userTags)) ).toList(); + if (request.getFollowingOnly()) { + List followingUserIds = userFollowRepository.findAllByFollower(user).stream() + .map(follow -> follow.getUser().getId()).toList(); + reviewDtos = reviewDtos.stream() + .filter(review -> followingUserIds.contains(review.getReviewerId())).toList(); + } + return ReadReviewResponseDto.of(latestReviewCount, reviewDtos); } From e5631f2c058cd7087eb1158b37102ff1a8d17d5e Mon Sep 17 00:00:00 2001 From: feel-coding Date: Sat, 24 Feb 2024 16:49:58 +0900 Subject: [PATCH 2/3] =?UTF-8?q?test:=20=EA=B8=B0=EC=A1=B4=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95=20#11?= =?UTF-8?q?8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/com/cvsgo/controller/ReviewControllerTest.java | 5 +++-- src/test/java/com/cvsgo/repository/ReviewRepositoryTest.java | 2 +- src/test/java/com/cvsgo/service/ReviewServiceTest.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/cvsgo/controller/ReviewControllerTest.java b/src/test/java/com/cvsgo/controller/ReviewControllerTest.java index a6debf80..eb93e221 100644 --- a/src/test/java/com/cvsgo/controller/ReviewControllerTest.java +++ b/src/test/java/com/cvsgo/controller/ReviewControllerTest.java @@ -158,7 +158,7 @@ void respond_409_when_user_requests_duplicate_product_review() throws Exception @DisplayName("리뷰 조회에 성공하면 HTTP 200을 응답한다.") void respond_200_when_success_to_read_reviews() throws Exception { ReadReviewRequestDto requestDto = new ReadReviewRequestDto(ReviewSortBy.LIKE, - List.of(1L, 2L, 3L), List.of(2L), List.of(4, 5)); + List.of(1L, 2L, 3L), List.of(2L), List.of(4, 5), null); List reviews = List.of(responseDto1, responseDto2); @@ -176,7 +176,8 @@ void respond_200_when_success_to_read_reviews() throws Exception { fieldWithPath("sortBy").type(JsonFieldType.STRING).description("정렬 기준").optional(), fieldWithPath("categoryIds").type(JsonFieldType.ARRAY).description("상품 카테고리 ID 목록").optional(), fieldWithPath("tagIds").type(JsonFieldType.ARRAY).description("태그 ID 목록").optional(), - fieldWithPath("ratings").type(JsonFieldType.ARRAY).description("별점 목록").optional() + fieldWithPath("ratings").type(JsonFieldType.ARRAY).description("별점 목록").optional(), + fieldWithPath("followingOnly").type(JsonFieldType.BOOLEAN).description("팔로우하는 사용자의 리뷰만 조회할지 여부").optional() ), relaxedResponseFields( fieldWithPath("data.latestReviewCount").type(JsonFieldType.NUMBER).description("최근 7일간 작성된 리뷰 개수"), diff --git a/src/test/java/com/cvsgo/repository/ReviewRepositoryTest.java b/src/test/java/com/cvsgo/repository/ReviewRepositoryTest.java index f351f968..bc010c5b 100644 --- a/src/test/java/com/cvsgo/repository/ReviewRepositoryTest.java +++ b/src/test/java/com/cvsgo/repository/ReviewRepositoryTest.java @@ -158,7 +158,7 @@ void succeed_to_update_review_images() { void succeed_to_read_reviews() { reviewRepository.flush(); ReadReviewRequestDto requestDto = new ReadReviewRequestDto(null, List.of(), List.of(), - List.of(3, 4, 5)); + List.of(3, 4, 5), null); List reviews = reviewRepository.findAllByFilter(user1, requestDto, PageRequest.of(0, 20)); assertThat(reviews.size()).isEqualTo(1); diff --git a/src/test/java/com/cvsgo/service/ReviewServiceTest.java b/src/test/java/com/cvsgo/service/ReviewServiceTest.java index ded34953..a891d364 100644 --- a/src/test/java/com/cvsgo/service/ReviewServiceTest.java +++ b/src/test/java/com/cvsgo/service/ReviewServiceTest.java @@ -493,7 +493,7 @@ void should_throw_NotFoundException_when_delete_review_but_review_does_not_exist new ArrayList<>()); ReadReviewRequestDto searchReviewRequest = new ReadReviewRequestDto(null, null, - null, null); + null, null, null); ReadReviewQueryDto readReviewQueryDto = new ReadReviewQueryDto(1L, 2L, "불닭볶음면큰컵", "삼양", "https://어쩌구저쩌구/products/불닭볶음면.png", From 60772bdcd38fd33d938492804998d144fd0bd0ad Mon Sep 17 00:00:00 2001 From: chaewss Date: Mon, 26 Feb 2024 15:00:27 +0900 Subject: [PATCH 3/3] =?UTF-8?q?PR=EC=8B=9C=20=EA=B2=B0=EA=B3=BC=20report?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pull-request.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index d658acb8..dbd226d4 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -4,6 +4,10 @@ on: pull_request: branches: [ "develop" ] +permissions: + checks: write + pull-requests: write + jobs: test: runs-on: ubuntu-latest @@ -25,3 +29,9 @@ jobs: run: | ./gradlew test --tests "com.cvsgo.controller.*" ./gradlew test --tests "com.cvsgo.service.*" + + - name: Report test result + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: 'build/test-results/**/*.xml'