Skip to content

Commit

Permalink
Merge pull request #119 from cvs-go/feature#118
Browse files Browse the repository at this point in the history
팔로우한 사용자의 리뷰 목록 조회 기능 추가
  • Loading branch information
chaewss authored Mar 25, 2024
2 parents 97983b5 + 60772bd commit 27b9f4d
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
pull_request:
branches: [ "develop" ]

permissions:
checks: write
pull-requests: write

jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -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'
5 changes: 4 additions & 1 deletion src/main/java/com/cvsgo/dto/review/ReadReviewRequestDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ public class ReadReviewRequestDto {

private final List<Integer> ratings;

private final Boolean followingOnly;

public ReadReviewRequestDto(ReviewSortBy sortBy, List<Long> categoryIds, List<Long> tagIds,
List<Integer> ratings) {
List<Integer> ratings, Boolean followingOnly) {
this.sortBy = sortBy;
this.categoryIds = categoryIds;
this.tagIds = tagIds;
this.ratings = ratings;
this.followingOnly = followingOnly != null && followingOnly;
}
}
3 changes: 3 additions & 0 deletions src/main/java/com/cvsgo/repository/UserFollowRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -11,4 +12,6 @@ public interface UserFollowRepository extends JpaRepository<UserFollow, Long> {

Optional<UserFollow> findByUserAndFollower(User user, User follower);

List<UserFollow> findAllByFollower(User follower);

}
10 changes: 10 additions & 0 deletions src/main/java/com/cvsgo/service/ReviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,6 +69,8 @@ public class ReviewService {

private final UserRepository userRepository;

private final UserFollowRepository userFollowRepository;

/**
* 리뷰를 추가합니다.
*
Expand Down Expand Up @@ -161,6 +164,13 @@ public ReadReviewResponseDto readReviewList(User user, ReadReviewRequestDto requ
getUserTags(reviewDto.getReviewerId(), userTags))
).toList();

if (request.getFollowingOnly()) {
List<Long> 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);
}

Expand Down
5 changes: 3 additions & 2 deletions src/test/java/com/cvsgo/controller/ReviewControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReviewDto> reviews = List.of(responseDto1, responseDto2);

Expand All @@ -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일간 작성된 리뷰 개수"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReadReviewQueryDto> reviews = reviewRepository.findAllByFilter(user1, requestDto,
PageRequest.of(0, 20));
assertThat(reviews.size()).isEqualTo(1);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/cvsgo/service/ReviewServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 27b9f4d

Please sign in to comment.