-
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: 리뷰 목록 재구현 #293
[BE] feat: 리뷰 목록 재구현 #293
Changes from 1 commit
212734e
81202e3
cb54dd8
8f1354d
b8595ed
5a2b975
76fb0ed
b7b6d1d
e66bcad
a1c68c1
113de8a
9b78bfb
6dd97b9
18a3911
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package reviewme.question.domain; | ||
|
||
public enum OptionType { | ||
CATEGORY, | ||
KEYWORD, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package reviewme.question.repository; | ||
|
||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import reviewme.question.domain.OptionItem; | ||
import reviewme.question.domain.OptionType; | ||
|
||
@Repository | ||
public interface OptionRepository extends JpaRepository<OptionItem, Long> { | ||
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. 네이밍은 도메인과 일치 시키는 것이 나을 것 같아요 |
||
|
||
List<OptionItem> findAllByOptionType(OptionType optionType); | ||
|
||
boolean existsByOptionTypeAndId(OptionType optionType, long id); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package reviewme.review.repository; | ||
|
||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
import reviewme.review.domain.Review2; | ||
|
||
@Repository | ||
public interface Review2Repository extends JpaRepository<Review2, Long> { | ||
|
||
@Query("SELECT r FROM Review2 r WHERE r.reviewGroupId=:reviewGroupId ORDER BY r.createdAt DESC") | ||
List<Review2> findReceivedReviewsByGroupId(long reviewGroupId); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import java.util.List; | ||
import reviewme.review.domain.ReviewContent; | ||
import reviewme.review.domain.TextAnswer; | ||
|
||
public class ReviewPreviewGenerator { | ||
|
||
|
@@ -17,4 +18,15 @@ public String generatePreview(List<ReviewContent> reviewContents) { | |
} | ||
return answer; | ||
} | ||
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. 이 부분 이제 없애주세용~ |
||
|
||
public String generatePreview2(List<TextAnswer> reviewTextAnswers) { | ||
if (reviewTextAnswers.isEmpty()) { | ||
return ""; | ||
} | ||
String answer = reviewTextAnswers.get(0).getText(); | ||
if (answer.length() > PREVIEW_LENGTH) { | ||
return answer.substring(0, PREVIEW_LENGTH); | ||
} | ||
return answer; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,12 @@ | |
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import reviewme.keyword.repository.KeywordRepository; | ||
import reviewme.question.domain.OptionType; | ||
import reviewme.question.domain.Question; | ||
import reviewme.question.repository.OptionRepository; | ||
import reviewme.review.domain.CheckboxAnswer; | ||
import reviewme.review.domain.Review; | ||
import reviewme.review.domain.Review2; | ||
import reviewme.review.domain.ReviewContent; | ||
import reviewme.review.domain.ReviewKeyword; | ||
import reviewme.review.domain.exception.ReviewGroupNotFoundByGroupAccessCodeException; | ||
|
@@ -17,13 +21,14 @@ | |
import reviewme.review.dto.request.CreateReviewRequest; | ||
import reviewme.review.dto.response.KeywordResponse; | ||
import reviewme.review.dto.response.QuestionSetupResponse; | ||
import reviewme.review.dto.response.ReceivedReviewKeywordsResponse; | ||
import reviewme.review.dto.response.ReceivedReviewCategoryResponse; | ||
import reviewme.review.dto.response.ReceivedReviewResponse; | ||
import reviewme.review.dto.response.ReceivedReviewsResponse; | ||
import reviewme.review.dto.response.ReviewContentResponse; | ||
import reviewme.review.dto.response.ReviewDetailResponse; | ||
import reviewme.review.dto.response.ReviewSetupResponse; | ||
import reviewme.review.repository.QuestionRepository; | ||
import reviewme.review.repository.Review2Repository; | ||
import reviewme.review.repository.ReviewKeywordRepository; | ||
import reviewme.review.repository.ReviewRepository; | ||
import reviewme.reviewgroup.domain.ReviewGroup; | ||
|
@@ -38,6 +43,8 @@ public class ReviewService { | |
private final ReviewGroupRepository reviewGroupRepository; | ||
private final QuestionRepository questionRepository; | ||
private final KeywordRepository keywordRepository; | ||
private final OptionRepository optionRepository; | ||
private final Review2Repository review2Repository; | ||
|
||
private final ReviewCreationQuestionValidator reviewCreationQuestionValidator; | ||
private final ReviewCreationKeywordValidator reviewCreationKeywordValidator; | ||
|
@@ -148,25 +155,31 @@ public ReceivedReviewsResponse findReceivedReviews(String groupAccessCode) { | |
ReviewGroup reviewGroup = reviewGroupRepository.findByGroupAccessCode(groupAccessCode) | ||
.orElseThrow(() -> new ReviewGroupNotFoundByGroupAccessCodeException(groupAccessCode)); | ||
List<ReceivedReviewResponse> reviewResponses = | ||
reviewRepository.findReceivedReviewsByGroupId(reviewGroup.getId()) | ||
review2Repository.findReceivedReviewsByGroupId(reviewGroup.getId()) | ||
.stream() | ||
.map(this::createReceivedReviewResponse) | ||
.toList(); | ||
return new ReceivedReviewsResponse(reviewGroup.getReviewee(), reviewGroup.getProjectName(), reviewResponses); | ||
} | ||
|
||
private ReceivedReviewResponse createReceivedReviewResponse(Review review) { | ||
List<ReceivedReviewKeywordsResponse> keywordsResponses = | ||
reviewKeywordRepository.findAllByReviewId(review.getId()) | ||
.stream() | ||
.map(reviewKeyword -> keywordRepository.getKeywordById(reviewKeyword.getKeywordId())) | ||
.map(keyword -> new ReceivedReviewKeywordsResponse(keyword.getId(), keyword.getContent())) | ||
.toList(); | ||
private ReceivedReviewResponse createReceivedReviewResponse(Review2 review) { | ||
CheckboxAnswer checkboxAnswer = review.getCheckboxAnswers() | ||
.stream() | ||
.filter(answer -> optionRepository.existsByOptionTypeAndId(OptionType.CATEGORY, answer.getSelectedOptionIds().get(0))) | ||
.findFirst() | ||
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. 이 부분 SQL 쿼리로 하면 한 번에 나가지 않을까요 ? 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. 네이티브 쿼리를 사용해서하면 어떻게 해볼 수 있을 것 같은데.. 머리 좀 굴려보고 반영할게요..!😂 |
||
.orElseThrow(); | ||
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. ㅋㅋㅋㅋㅋㅋㅋㅋㅋ그저 던졌군요😱 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. 무엇을 Throw 하나요?😱 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. ㅋㅋㅋㅋㅋㅋㅋㅋㅋ냅다 던지기.. 반영하겠습니다😱 |
||
|
||
List<ReceivedReviewCategoryResponse> categoryResponses = | ||
optionRepository.findAllById(checkboxAnswer.getSelectedOptionIds()) | ||
.stream() | ||
.map(optionItem -> new ReceivedReviewCategoryResponse(optionItem.getId(), optionItem.getContent())) | ||
.toList(); | ||
|
||
return new ReceivedReviewResponse( | ||
review.getId(), | ||
review.getCreatedAt().toLocalDate(), | ||
reviewPreviewGenerator.generatePreview(review.getReviewContents()), | ||
keywordsResponses | ||
reviewPreviewGenerator.generatePreview2(review.getTextAnswers()), | ||
categoryResponses | ||
); | ||
} | ||
} |
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.
OptionItemRepository 로 이름 변경해주세용~