-
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 구현 #102
Changes from all commits
c5c6fce
a962241
1c2ce1f
749e82b
910e337
51393ad
6150e00
657ac4d
d0b7fe4
bbcb419
8ac3b54
da1e415
ed5a676
9a104ab
5db0782
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 |
---|---|---|
|
@@ -5,12 +5,15 @@ | |
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Table(name = "github_id_reviewer_group") | ||
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. 테이블 명시 👍🏻 |
||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
public class GithubIdReviewerGroup { | ||
|
@@ -23,6 +26,7 @@ public class GithubIdReviewerGroup { | |
private GithubId githubId; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "reviewer_group_id", nullable = false) | ||
private ReviewerGroup reviewerGroup; | ||
|
||
public GithubIdReviewerGroup(GithubId githubId, ReviewerGroup reviewerGroup) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package reviewme.review.exception; | ||
|
||
import reviewme.global.exception.NotFoundException; | ||
|
||
public class QuestionNotFoundException extends NotFoundException { | ||
|
||
public QuestionNotFoundException() { | ||
super("질문이 존재하지 않습니다."); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package reviewme.review.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import reviewme.review.domain.Question; | ||
import reviewme.review.exception.QuestionNotFoundException; | ||
|
||
@Repository | ||
public interface QuestionRepository extends JpaRepository<Question, Long> { | ||
|
||
default Question getQuestionById(long id) { | ||
return findById(id).orElseThrow(QuestionNotFoundException::new); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package reviewme.review.service; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
@@ -11,13 +12,15 @@ | |
import reviewme.member.domain.ReviewerGroup; | ||
import reviewme.member.repository.MemberRepository; | ||
import reviewme.member.repository.ReviewerGroupRepository; | ||
import reviewme.review.domain.Question; | ||
import reviewme.review.domain.Review; | ||
import reviewme.review.domain.ReviewContent; | ||
import reviewme.review.dto.request.CreateReviewRequest; | ||
import reviewme.review.dto.response.ReviewDetailResponse; | ||
import reviewme.review.dto.response.ReviewDetailReviewContentResponse; | ||
import reviewme.review.dto.response.ReviewDetailReviewerGroupResponse; | ||
import reviewme.review.exception.ReviewUnAuthorizedException; | ||
import reviewme.review.repository.QuestionRepository; | ||
import reviewme.review.repository.ReviewContentRepository; | ||
import reviewme.review.repository.ReviewRepository; | ||
|
||
|
@@ -29,11 +32,33 @@ public class ReviewService { | |
private final MemberRepository memberRepository; | ||
private final ReviewerGroupRepository reviewerGroupRepository; | ||
private final ReviewContentRepository reviewContentRepository; | ||
private final QuestionRepository questionRepository; | ||
private final KeywordRepository keywordRepository; | ||
|
||
@Transactional | ||
public Long createReview(CreateReviewRequest request) { | ||
return null; | ||
ReviewerGroup reviewerGroup = reviewerGroupRepository.getReviewerGroupById(request.reviewerGroupId()); | ||
Member reviewer = memberRepository.getMemberById(request.reviewerId()); | ||
|
||
List<Keyword> keywordList = request.keywords() | ||
.stream() | ||
.map(keywordRepository::getKeywordById) | ||
.toList(); | ||
|
||
Review review = new Review(reviewer, reviewerGroup.getReviewee(), | ||
reviewerGroup, keywordList, LocalDateTime.now()); | ||
Review savedReview = reviewRepository.save(review); | ||
Comment on lines
+48
to
+50
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. 리뷰이 부분에 들어갈 인자를 reviewerGroup 에서 빼서 넣어주셨는데요! 그런데 그렇게 한다면, 리뷰를 리뷰어 그룹에 추가할 때 검증하는 함수인 addReview 에서 '추가될 리뷰의 리뷰이와 리뷰어 그룹의 리뷰이가 같은지 검증하는' 부분이 무용지물이 될 것 같아요! 그러니 MemverRepository 로부터 찾아서 넣어주는건 어떨까요? // ReviwerGroup.class
public void addReview(Review review) {
Member reviewer = review.getReviewer();
if (isDeadlineExceeded(review.getCreatedAt())) {
throw new DeadlineExpiredException();
}
if (hasSubmittedReviewBy(reviewer)) {
throw new ReviewAlreadySubmittedException();
}
if (reviewerGithubIds.doesNotContain(reviewer)) {
throw new GithubReviewerGroupUnAuthorizedException();
}
if (!review.getReviewee().equals(reviewee)) { // ❗️이부분
throw new RevieweeMismatchException();
}
reviews.add(review);
} 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. Member reviewer = memberRepository.getMemberById(request.reviewerId());
Member reviewee = memberRepository.getMemberById(reviewerGroup.getReviewee().getId()); 이전에 위의 방식으로 했었는데요, 어차피 리뷰이를 따로 받는게 아니라 사실상 리뷰어 그룹에 있는 리뷰이를 사용할거라면 두 방식에 차이가 없어 보여요. 차라리 리뷰 생성자로 리뷰이를 받지 않고, 리뷰 그룹에서 꺼내 쓰는게 나을 것 같기도 하고, 어떤 방식이든 사실 순환참조 때문에 '추가될 리뷰의 리뷰이와 리뷰어 그룹의 리뷰이가 같은지 검증하는' 부분이 의미가 없긴 할 것 같아요. 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. 오 동의합니다. 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. '리뷰어 그룹으로부터 리뷰이를 받아오도록 리팩터링하는건 어떨까?' 라는 생각이 든다! |
||
|
||
request.reviewContents() | ||
.forEach(contentsRequest -> { | ||
Question question = questionRepository.getQuestionById(contentsRequest.questionId()); | ||
String answer = contentsRequest.answer(); | ||
|
||
ReviewContent reviewContent = new ReviewContent(savedReview, question, answer); | ||
reviewContentRepository.save(reviewContent); | ||
}); | ||
|
||
return savedReview.getId(); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
|
This file was deleted.
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.
👍