-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BE] feat: 받은 리뷰 요약 조회 API 구현 #796
Changes from 6 commits
95be71e
73f587d
530cebb
3231afa
cc6e147
8b0742c
6533eb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,32 @@ | ||
package reviewme.review.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import reviewme.review.repository.ReviewRepository; | ||
import reviewme.review.service.dto.response.list.ReceivedReviewsSummaryResponse; | ||
import reviewme.review.service.exception.ReviewGroupNotFoundByReviewRequestCodeException; | ||
import reviewme.reviewgroup.domain.ReviewGroup; | ||
import reviewme.reviewgroup.repository.ReviewGroupRepository; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReviewSummaryService { | ||
|
||
private final ReviewGroupRepository reviewGroupRepository; | ||
private final ReviewRepository reviewRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public ReceivedReviewsSummaryResponse getReviewSummary(String reviewRequestCode) { | ||
return null; | ||
ReviewGroup reviewGroup = reviewGroupRepository.findByReviewRequestCode(reviewRequestCode) | ||
.orElseThrow(() -> new ReviewGroupNotFoundByReviewRequestCodeException(reviewRequestCode)); | ||
|
||
int totalReviewCount = reviewRepository.countByReviewGroupId(reviewGroup.getId()); | ||
|
||
return new ReceivedReviewsSummaryResponse( | ||
reviewGroup.getProjectName(), | ||
reviewGroup.getReviewee(), | ||
totalReviewCount | ||
); | ||
Comment on lines
+26
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [이건 그냥 소감] |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package reviewme.review.service; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static reviewme.fixture.QuestionFixture.서술형_필수_질문; | ||
import static reviewme.fixture.ReviewGroupFixture.리뷰_그룹; | ||
import static reviewme.fixture.SectionFixture.항상_보이는_섹션; | ||
import static reviewme.fixture.TemplateFixture.템플릿; | ||
|
||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import reviewme.question.domain.Question; | ||
import reviewme.question.repository.QuestionRepository; | ||
import reviewme.review.domain.Review; | ||
import reviewme.review.repository.ReviewRepository; | ||
import reviewme.review.service.dto.response.list.ReceivedReviewsSummaryResponse; | ||
import reviewme.review.service.exception.ReviewGroupNotFoundByReviewRequestCodeException; | ||
import reviewme.reviewgroup.domain.ReviewGroup; | ||
import reviewme.reviewgroup.repository.ReviewGroupRepository; | ||
import reviewme.support.ServiceTest; | ||
import reviewme.template.domain.Section; | ||
import reviewme.template.domain.Template; | ||
import reviewme.template.repository.SectionRepository; | ||
import reviewme.template.repository.TemplateRepository; | ||
|
||
@ServiceTest | ||
class ReviewSummaryServiceTest { | ||
|
||
@Autowired | ||
private ReviewSummaryService reviewSummaryService; | ||
|
||
@Autowired | ||
private ReviewGroupRepository reviewGroupRepository; | ||
|
||
@Autowired | ||
private ReviewRepository reviewRepository; | ||
|
||
@Autowired | ||
private TemplateRepository templateRepository; | ||
|
||
@Autowired | ||
private SectionRepository sectionRepository; | ||
|
||
@Autowired | ||
private QuestionRepository questionRepository; | ||
|
||
@Test | ||
void 리뷰_그룹에_등록된_리뷰_요약_정보를_반환한다() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다른 reviewGroup의 review가 아닌 내 reviewGroup의 review 갯수만 반환하는지 확인하는 로직이 필요할 것 같아요~ 쓰고보니 repository의 countByReviewGroupId에 대한 테스트 메서드를 만드는 게 더 맞겠다는 생각도 드네요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 지금 다른 레포지토리에서 JPA가 만들어준 메서드는 따로 테스트 하고 있지 않아서.. 우선 기존 테스트에 그룹 하나 추가하는 걸로도 알 수 있을 것 같아 추가했어요~ |
||
// given | ||
Question question = questionRepository.save(서술형_필수_질문()); | ||
Section section = sectionRepository.save(항상_보이는_섹션(List.of(question.getId()))); | ||
Template template = templateRepository.save(템플릿(List.of(section.getId()))); | ||
|
||
ReviewGroup reviewGroup1 = reviewGroupRepository.save(리뷰_그룹()); | ||
ReviewGroup reviewGroup2 = reviewGroupRepository.save(리뷰_그룹("reReCo", "groupCo")); | ||
|
||
List<Review> reviews = List.of( | ||
new Review(template.getId(), reviewGroup1.getId(), List.of()), | ||
new Review(template.getId(), reviewGroup1.getId(), List.of()), | ||
new Review(template.getId(), reviewGroup1.getId(), List.of()) | ||
); | ||
reviewRepository.saveAll(reviews); | ||
reviewRepository.save(new Review(template.getId(), reviewGroup2.getId(), List.of())); | ||
|
||
// when | ||
ReceivedReviewsSummaryResponse actual = reviewSummaryService.getReviewSummary( | ||
reviewGroup1.getReviewRequestCode()); | ||
// then | ||
assertAll( | ||
() -> assertThat(actual.projectName()).isEqualTo(reviewGroup1.getProjectName()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 개행해주세욧! |
||
() -> assertThat(actual.revieweeName()).isEqualTo(reviewGroup1.getReviewee()), | ||
() -> assertThat(actual.totalReviewCount()).isEqualTo(reviews.size()) | ||
); | ||
} | ||
|
||
@Test | ||
void 리뷰_요약_정보_조회시_리뷰_요청_코드가_존재하지_않는_경우_예외가_발생한다() { | ||
// given | ||
ReviewGroup reviewGroup = reviewGroupRepository.save(리뷰_그룹()); | ||
|
||
// when, then | ||
assertThatThrownBy(() -> reviewSummaryService.getReviewSummary( | ||
reviewGroup.getReviewRequestCode() + "wrong")) | ||
.isInstanceOf(ReviewGroupNotFoundByReviewRequestCodeException.class); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
인덱스 걸려있으면 빠를까요? 아래 JPQL과 쿼리 차이나 성능 차이가 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewGroupId에 인덱스 걸려있어서 현재 쿼리로 인덱스 걸리지 않나요?