Skip to content
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] refactor: 리뷰 상세 조회 dto 개선 #847

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

public record OptionItemAnswerResponse(
long optionId,
String content,
boolean isChecked
String content
) {
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package reviewme.review.service.dto.response.detail;

import jakarta.annotation.Nullable;
import java.util.List;
import reviewme.question.domain.QuestionType;

public record QuestionAnswerResponse(
long questionId,
boolean required,
QuestionType questionType,
String content,
@Nullable OptionGroupAnswerResponse optionGroup,
String questionContents,
@Nullable List<OptionItemAnswerResponse> options,
@Nullable String answer
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
public record SectionAnswerResponse(
long sectionId,
String header,
List<QuestionAnswerResponse> questions
List<QuestionAnswerResponse> reviews
) {

public boolean hasAnsweredQuestion() {
return !questions.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import reviewme.review.domain.CheckboxAnswerSelectedOption;
import reviewme.review.domain.Review;
import reviewme.review.domain.TextAnswer;
import reviewme.review.service.dto.response.detail.OptionGroupAnswerResponse;
import reviewme.review.service.dto.response.detail.OptionItemAnswerResponse;
import reviewme.review.service.dto.response.detail.QuestionAnswerResponse;
import reviewme.review.service.dto.response.detail.ReviewDetailResponse;
Expand Down Expand Up @@ -53,7 +52,7 @@ public ReviewDetailResponse mapToReviewDetailResponse(Review review, ReviewGroup
List<SectionAnswerResponse> sectionResponses = sections.stream()
.map(section -> mapToSectionResponse(review, section, questions,
optionGroupsByQuestion, optionItemsByOptionGroup))
.filter(sectionResponse -> !sectionResponse.questions().isEmpty())
.filter(sectionResponse -> !sectionResponse.reviews().isEmpty())
.toList();

return new ReviewDetailResponse(
Expand Down Expand Up @@ -107,22 +106,15 @@ private QuestionAnswerResponse mapToCheckboxQuestionResponse(Review review,

List<OptionItemAnswerResponse> optionItemResponse = optionItems.stream()
.filter(optionItem -> selectedOptionIds.contains(optionItem.getId()))
.map(optionItem -> new OptionItemAnswerResponse(optionItem.getId(), optionItem.getContent(), true))
.map(optionItem -> new OptionItemAnswerResponse(optionItem.getId(), optionItem.getContent()))
.toList();

OptionGroupAnswerResponse optionGroupAnswerResponse = new OptionGroupAnswerResponse(
optionGroup.getId(),
optionGroup.getMinSelectionCount(),
optionGroup.getMaxSelectionCount(),
optionItemResponse
);

return new QuestionAnswerResponse(
question.getId(),
question.isRequired(),
question.getQuestionType(),
question.getContent(),
optionGroupAnswerResponse,
optionItemResponse,
null
);
}
Expand Down
27 changes: 11 additions & 16 deletions backend/src/test/java/reviewme/api/ReviewApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,17 @@ class ReviewApiTest extends ApiTest {
fieldWithPath("sections[].sectionId").description("섹션 ID"),
fieldWithPath("sections[].header").description("섹션 제목"),

fieldWithPath("sections[].questions[]").description("질문 목록"),
fieldWithPath("sections[].questions[].questionId").description("질문 ID"),
fieldWithPath("sections[].questions[].required").description("필수 여부"),
fieldWithPath("sections[].questions[].content").description("질문 내용"),
fieldWithPath("sections[].questions[].questionType").description("질문 타입"),

fieldWithPath("sections[].questions[].optionGroup").description("옵션 그룹").optional(),
fieldWithPath("sections[].questions[].optionGroup.optionGroupId").description("옵션 그룹 ID"),
fieldWithPath("sections[].questions[].optionGroup.minCount").description("최소 선택 개수"),
fieldWithPath("sections[].questions[].optionGroup.maxCount").description("최대 선택 개수"),

fieldWithPath("sections[].questions[].optionGroup.options[]").description("선택 항목 목록"),
fieldWithPath("sections[].questions[].optionGroup.options[].optionId").description("선택 항목 ID"),
fieldWithPath("sections[].questions[].optionGroup.options[].content").description("선택 항목 내용"),
fieldWithPath("sections[].questions[].optionGroup.options[].isChecked").description("선택 여부"),
fieldWithPath("sections[].questions[].answer").description("서술형 답변").optional(),
fieldWithPath("sections[].reviews[]").description("리뷰 목록"),
fieldWithPath("sections[].reviews[].questionId").description("질문 ID"),
fieldWithPath("sections[].reviews[].required").description("필수 여부"),
fieldWithPath("sections[].reviews[].questionContents").description("질문 내용"),
fieldWithPath("sections[].reviews[].questionType").description("질문 타입"),

fieldWithPath("sections[].reviews[].options").description("선택 항목 목록").optional(),
fieldWithPath("sections[].reviews[].options[]").description("선택 항목 목록"),
fieldWithPath("sections[].reviews[].options[].optionId").description("선택 항목 ID"),
fieldWithPath("sections[].reviews[].options[].content").description("선택 항목 내용"),
fieldWithPath("sections[].reviews[].answer").description("서술형 답변").optional(),
};

RestDocumentationResultHandler handler = document(
Expand Down
54 changes: 29 additions & 25 deletions backend/src/test/java/reviewme/api/TemplateFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import java.time.LocalDate;
import java.util.List;
import reviewme.question.domain.QuestionType;
import reviewme.review.service.dto.response.detail.OptionGroupAnswerResponse;
import reviewme.review.service.dto.response.detail.OptionItemAnswerResponse;
import reviewme.review.service.dto.response.detail.QuestionAnswerResponse;
import reviewme.review.service.dto.response.detail.SectionAnswerResponse;
import reviewme.review.service.dto.response.detail.ReviewDetailResponse;
import reviewme.review.service.dto.response.detail.SectionAnswerResponse;
import reviewme.template.domain.VisibleType;
import reviewme.template.service.dto.response.OptionGroupResponse;
import reviewme.template.service.dto.response.OptionItemResponse;
Expand Down Expand Up @@ -74,36 +73,41 @@ public static TemplateResponse templateResponse() {

public static ReviewDetailResponse templateAnswerResponse() {
// Section 1
List<OptionItemAnswerResponse> firstOptionAnswers = List.of(
new OptionItemAnswerResponse(1, "커뮤니케이션, 협업 능력 (ex: 팀원간의 원활한 정보 공유, 명확한 의사소통)", true),
new OptionItemAnswerResponse(2, "문제 해결 능력 (ex: 프로젝트 중 만난 버그/오류를 분석하고 이를 해결하는 능력)", false),
new OptionItemAnswerResponse(3, "시간 관리 능력 (ex: 일정과 마감 기한 준수, 업무의 우선 순위 분배)", false)
List<OptionItemAnswerResponse> optionAnswer = List.of(
new OptionItemAnswerResponse(1, "커뮤니케이션, 협업 능력 (ex: 팀원간의 원활한 정보 공유, 명확한 의사소통)"),
new OptionItemAnswerResponse(2, "문제 해결 능력 (ex: 프로젝트 중 만난 버그/오류를 분석하고 이를 해결하는 능력)"),
new OptionItemAnswerResponse(3, "시간 관리 능력 (ex: 일정과 마감 기한 준수, 업무의 우선 순위 분배)")
);
OptionGroupAnswerResponse firstOptionGroupAnswer = new OptionGroupAnswerResponse(1, 1, 2, firstOptionAnswers);
QuestionAnswerResponse firstQuestionAnswer = new QuestionAnswerResponse(
1, true, QuestionType.CHECKBOX, "프로젝트 기간 동안, 아루의 강점이 드러났던 순간을 선택해주세요.", firstOptionGroupAnswer, null
);
SectionAnswerResponse firstSectionAnswer = new SectionAnswerResponse(
1, "프로젝트 기간 동안, 아루의 강점이 드러났던 순간을 선택해주세요.", List.of(firstQuestionAnswer)
1, true, QuestionType.CHECKBOX, "프로젝트 기간 동안, 아루의 강점이 드러났던 순간을 선택해주세요.", optionAnswer, null
);

// Section 2
List<OptionItemAnswerResponse> secondOptionAnswers = List.of(
new OptionItemAnswerResponse(4, "반대 의견을 내더라도 듣는 사람이 기분 나쁘지 않게 이야기해요.", true),
new OptionItemAnswerResponse(5, "팀원들의 의견을 잘 모아서 회의가 매끄럽게 진행되도록 해요.", false),
new OptionItemAnswerResponse(6, "팀의 분위기를 주도해요.", true)
);
OptionGroupAnswerResponse secondOptionGroupAnswer = new OptionGroupAnswerResponse(2, 1, 3, secondOptionAnswers);
QuestionAnswerResponse secondQuestionAnswer = new QuestionAnswerResponse(
2, true, QuestionType.CHECKBOX, "커뮤니케이션, 협업 능력에서 어떤 부분이 인상 깊었는지 선택해주세요.", secondOptionGroupAnswer,
null
);
SectionAnswerResponse secondSectionAnswer = new SectionAnswerResponse(
2, "커뮤니케이션, 협업 능력에서 어떤 부분이 인상 깊었는지 선택해주세요.", List.of(secondQuestionAnswer)
QuestionAnswerResponse secondQuestionAnswer = new QuestionAnswerResponse(2, true, QuestionType.TEXT, "위에서 선택한 사항에 대해 조금 더 자세히 설명해주세요.", null, "나산초의 답변");

SectionAnswerResponse sectionAnswer = new SectionAnswerResponse(
1, "프로젝트 기간 동안, 아루의 강점이 드러났던 순간을 선택해주세요.", List.of(firstQuestionAnswer, secondQuestionAnswer)
);

return new ReviewDetailResponse(
1, "아루", "리뷰미", LocalDate.of(2024, 8, 1), List.of(firstSectionAnswer, secondSectionAnswer)
1, "아루", "리뷰미", LocalDate.of(2024, 8, 1), List.of(sectionAnswer)
);

// Section 2
// List<OptionItemAnswerResponse> secondOptionAnswers = List.of(
// new OptionItemAnswerResponse(4, "반대 의견을 내더라도 듣는 사람이 기분 나쁘지 않게 이야기해요."),
// new OptionItemAnswerResponse(5, "팀원들의 의견을 잘 모아서 회의가 매끄럽게 진행되도록 해요."),
// new OptionItemAnswerResponse(6, "팀의 분위기를 주도해요.")
// );
// QuestionAnswerResponse secondQuestionAnswer = new QuestionAnswerResponse(
// 2, true, QuestionType.CHECKBOX, "커뮤니케이션, 협업 능력에서 어떤 부분이 인상 깊었는지 선택해주세요.", secondOptionAnswers,
// null
// );
// SectionAnswerResponse secondSectionAnswer = new SectionAnswerResponse(
// 2, "커뮤니케이션, 협업 능력에서 어떤 부분이 인상 깊었는지 선택해주세요.", List.of(secondQuestionAnswer)
// );

// return new ReviewDetailResponse(
// 1, "아루", "리뷰미", LocalDate.of(2024, 8, 1), List.of(sectionAnswer, secondSectionAnswer)
// );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class NotAnsweredOptionalQuestion {
.extracting(SectionAnswerResponse::sectionId)
.containsExactly(section.getId()),
() -> assertThat(reviewDetail.sections())
.flatExtracting(SectionAnswerResponse::questions)
.flatExtracting(SectionAnswerResponse::reviews)
.extracting(QuestionAnswerResponse::questionId)
.containsExactly(question1.getId())
);
Expand Down