Skip to content

Commit

Permalink
feat: 질문 보조 설명 필드(description) 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
cutehumanS2 committed Jan 25, 2025
1 parent a399c9c commit 4a124d4
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 36 deletions.
12 changes: 6 additions & 6 deletions backend/src/main/java/com/cruru/DataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,23 @@ private void runDataLoader() {
applicantRepository.saveAll(applicants);

Question question1 = questionRepository.save(
new Question(LONG_ANSWER, "효과적인 학습 방식과 경험", 1, false, applyForm)
new Question(LONG_ANSWER, "효과적인 학습 방식과 경험", "지원자가 학습 과정에서 어떤 방식이 효과적이었는지와 관련 경험을 기술해주세요.", 1, false, applyForm)
);

Question question2 = questionRepository.save(
new Question(LONG_ANSWER, "성장 중 겪은 실패와 극복", 2, false, applyForm)
new Question(LONG_ANSWER, "성장 중 겪은 실패와 극복", "성장 과정에서 겪은 실패와 이를 극복하기 위한 노력, 배운 점을 서술해주세요.", 2, false, applyForm)
);

Question question3 = questionRepository.save(
new Question(LONG_ANSWER, "오랜 시간 몰입했던 경험 그리고 도전", 3, false, applyForm)
new Question(LONG_ANSWER, "오랜 시간 몰입했던 경험 그리고 도전", "몰입했던 경험과 이를 통해 얻은 결과 및 배운 점에 대해 서술해주세요.", 3, false, applyForm)
);

Question question4 = questionRepository.save(
new Question(LONG_ANSWER, "오랜 시간 몰입했던 경험 그리고 도전", 4, false, applyForm)
new Question(LONG_ANSWER, "오랜 시간 몰입했던 경험 그리고 도전", "우아한테크코스에 지원하게 된 계기와 프로그램을 통해 이루고 싶은 목표를 작성해주세요.", 4, false, applyForm)
);

Question question5 = questionRepository.save(
new Question(MULTIPLE_CHOICE, "지원 경로", 5, false, applyForm)
new Question(MULTIPLE_CHOICE, "지원 경로", "우아한테크코스를 알게 된 경로를 선택해주세요.", 5, false, applyForm)
);

Choice homepage = choiceRepository.save(new Choice("우아한테크코스 홈페이지", 1, question5));
Expand All @@ -134,7 +134,7 @@ private void runDataLoader() {
Choice socialMedia = choiceRepository.save(new Choice("소셜 미디어", 4, question5));

Question question6 = questionRepository.save(
new Question(SINGLE_CHOICE, "모든 문항에 답했는지 확인해주세요. 제출 후에 수정이 불가능합니다.", 6, false, applyForm)
new Question(SINGLE_CHOICE, "모든 문항에 답했는지 확인해주세요. 제출 후에 수정이 불가능합니다.", null, 6, false, applyForm)
);

Choice yes = choiceRepository.save(new Choice("네, 확인했습니다.", 1, question6));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public record QuestionCreateRequest(
@NotBlank(message = "질문 내용은 필수 값입니다.")
String question,

String description,

@Valid
List<ChoiceCreateRequest> choices,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public record QuestionResponse(
@JsonProperty("label")
String content,

String description,

int orderIndex,

@JsonProperty("choices")
Expand Down
6 changes: 6 additions & 0 deletions backend/src/main/java/com/cruru/question/domain/Question.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class Question implements SecureResource {

private String content;

@Column(columnDefinition = "TEXT")
private String description;

private Integer sequence;

private boolean required;
Expand All @@ -47,12 +50,14 @@ public class Question implements SecureResource {
public Question(
QuestionType questionType,
String content,
String description,
Integer sequence,
Boolean required,
ApplyForm applyForm
) {
this.questionType = questionType;
this.content = content;
this.description = description;
this.sequence = sequence;
this.required = required;
this.applyForm = applyForm;
Expand Down Expand Up @@ -98,6 +103,7 @@ public String toString() {
"id=" + id +
", questionType=" + questionType +
", content='" + content + '\'' +
", description='" + description + '\'' +
", sequence=" + sequence +
", applyForm=" + applyForm +
'}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private Question toQuestion(QuestionCreateRequest request, ApplyForm applyForm)
return new Question(
QuestionType.valueOf(request.type()),
request.question(),
request.description(),
request.orderIndex(),
request.required(),
applyForm
Expand Down Expand Up @@ -75,6 +76,7 @@ private QuestionResponse toQuestionResponse(Question question) {
question.getId(),
question.getQuestionType().name(),
question.getContent(),
question.getDescription(),
question.getSequence(),
getChoiceResponses(question),
question.isRequired()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ class ApplyFormControllerTest extends ControllerTest {
fieldWithPath("id").description("질문의 id"),
fieldWithPath("type").description("질문 유형"),
fieldWithPath("label").description("질문의 내용"),
fieldWithPath("description").optional().description("질문 보조 설명"),
fieldWithPath("orderIndex").description("질문 순서"),
fieldWithPath("choices").description("질문의 선택지"),
fieldWithPath("required").description("질문 필수여부"),
};
fieldWithPath("required").description("질문 필수여부")
};

private static final FieldDescriptor[] CHOICE_FIELD_DESCRIPTORS = {
fieldWithPath("id").description("선택지의 id"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class DashboardControllerTest extends ControllerTest {
private static final FieldDescriptor[] QUESTION_FIELD_DESCRIPTORS = {
fieldWithPath("type").description("질문 유형"),
fieldWithPath("question").description("질문 내용"),
fieldWithPath("description").optional().description("질문 보조 설명"),
fieldWithPath("choices").description("질문의 선택지들"),
fieldWithPath("orderIndex").description("질문의 순서"),
fieldWithPath("required").description("질문의 필수여부")
Expand All @@ -78,9 +79,6 @@ class DashboardControllerTest extends ControllerTest {
fieldWithPath("orderIndex").description("선택지의 순서")
};

@Autowired
private ClubRepository clubRepository;

@Autowired
private DashboardRepository dashboardRepository;

Expand Down Expand Up @@ -117,37 +115,37 @@ private static Stream<QuestionCreateRequest> InvalidQuestionCreateRequest() {
String validQuestion = "객관식질문";
boolean validRequired = false;
return Stream.of(
new QuestionCreateRequest(null, validQuestion,
new QuestionCreateRequest(null, validQuestion, null,
validChoiceCreateRequests, validOrderIndex, validRequired
),
new QuestionCreateRequest("", validQuestion,
new QuestionCreateRequest("", validQuestion, null,
validChoiceCreateRequests, validOrderIndex, validRequired
),
new QuestionCreateRequest(validType, null,
new QuestionCreateRequest(validType, null, null,
validChoiceCreateRequests, validOrderIndex, validRequired
),
new QuestionCreateRequest(validType, "",
new QuestionCreateRequest(validType, "", null,
validChoiceCreateRequests, validOrderIndex, validRequired
),
new QuestionCreateRequest(validType, validQuestion,
new QuestionCreateRequest(validType, validQuestion, null,
List.of(new ChoiceCreateRequest(null, validOrderIndex)), validOrderIndex, validRequired
),
new QuestionCreateRequest(validType, validQuestion,
new QuestionCreateRequest(validType, validQuestion, null,
List.of(new ChoiceCreateRequest("", validOrderIndex)), validOrderIndex, validRequired
),
new QuestionCreateRequest(validType, validQuestion,
new QuestionCreateRequest(validType, validQuestion, null,
List.of(new ChoiceCreateRequest(validChoice, null)), validOrderIndex, validRequired
),
new QuestionCreateRequest(validType, validQuestion,
new QuestionCreateRequest(validType, validQuestion, null,
List.of(new ChoiceCreateRequest(validChoice, -1)), validOrderIndex, validRequired
),
new QuestionCreateRequest(validType, validQuestion,
new QuestionCreateRequest(validType, validQuestion, null,
validChoiceCreateRequests, null, validRequired
),
new QuestionCreateRequest(validType, validQuestion,
new QuestionCreateRequest(validType, validQuestion, null,
validChoiceCreateRequests, -1, validRequired
),
new QuestionCreateRequest(validType, validQuestion,
new QuestionCreateRequest(validType, validQuestion, null,
validChoiceCreateRequests, validOrderIndex, null
)
);
Expand All @@ -159,7 +157,7 @@ void create() {
// given
List<ChoiceCreateRequest> choiceCreateRequests = List.of(new ChoiceCreateRequest("선택지1", 1));
List<QuestionCreateRequest> questionCreateRequests = List.of(
new QuestionCreateRequest("DROPDOWN", "객관식질문1", choiceCreateRequests, 1, false));
new QuestionCreateRequest("DROPDOWN", "객관식질문1", null, choiceCreateRequests, 1, false));
DashboardCreateRequest request = new DashboardCreateRequest(
"크루루대시보드",
"# 공고 내용",
Expand Down Expand Up @@ -238,7 +236,7 @@ void create_invalidClub() {
// given
List<ChoiceCreateRequest> choiceCreateRequests = List.of(new ChoiceCreateRequest("선택지1", 1));
List<QuestionCreateRequest> questionCreateRequests = List.of(
new QuestionCreateRequest("DROPDOWN", "객관식질문1", choiceCreateRequests, 1, false));
new QuestionCreateRequest("DROPDOWN", "객관식질문1", null, choiceCreateRequests, 1, false));
DashboardCreateRequest request = new DashboardCreateRequest(
"크루루대시보드",
"# 공고 내용",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,15 @@ void create() {
// given
List<ChoiceCreateRequest> choiceCreateRequests = List.of(new ChoiceCreateRequest("선택지1", 1));
List<QuestionCreateRequest> questionCreateRequests = List.of(
new QuestionCreateRequest("DROPDOWN", "객관식질문1", choiceCreateRequests, 1, false));
new QuestionCreateRequest(
"DROPDOWN",
"객관식질문1",
"이 질문은 여러 선택지 중 하나를 선택하는 질문입니다.",
choiceCreateRequests,
1,
false
)
);
String title = "크루루대시보드";
String postingContent = "# 공고 내용";
LocalDateTime startDate = LocalDateFixture.oneDayLater();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class QuestionControllerTest extends ControllerTest {
private static final FieldDescriptor[] QUESTION_FIELD_DESCRIPTORS = {
fieldWithPath("type").description("질문의 유형"),
fieldWithPath("question").description("질문 내용"),
fieldWithPath("description").optional().description("질문 보조 설명"),
fieldWithPath("choices").description("질문의 선택지들"),
fieldWithPath("orderIndex").description("질문의 순서"),
fieldWithPath("required").description("질문의 필수 여부")
Expand Down Expand Up @@ -59,6 +60,7 @@ void updateById() {
new QuestionCreateRequest(
QuestionType.LONG_ANSWER.name(),
"new",
null,
List.of(new ChoiceCreateRequest("좋아하는 음식은?", 0)),
0,
true
Expand Down Expand Up @@ -94,6 +96,7 @@ void update_applyFormNotFound() {
new QuestionCreateRequest(
QuestionType.LONG_ANSWER.name(),
"new",
null,
List.of(new ChoiceCreateRequest("좋아하는 음식은?", 0)),
0,
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ void setUp() {
@Test
void sameIdUpdate() {
//given
Question question = new Question(DROPDOWN, "성별", 0, false, null);
Question question = new Question(DROPDOWN, "성별", null, 0, false, null);
Question saved = questionRepository.save(question);

//when
Question updateQuestion = new Question(saved.getId(), SHORT_ANSWER, "전공", 1, false, null);
Question updateQuestion = new Question(saved.getId(), SHORT_ANSWER, "전공", null, 1, false, null);
questionRepository.save(updateQuestion);

//then
Expand All @@ -43,8 +43,8 @@ void sameIdUpdate() {
@Test
void saveNoId() {
//given
Question question1 = new Question(DROPDOWN, "성별", 0, false, null);
Question question2 = new Question(SHORT_ANSWER, "전공", 1, false, null);
Question question1 = new Question(DROPDOWN, "성별", null, 0, false, null);
Question question2 = new Question(SHORT_ANSWER, "전공", null, 1, false, null);

//when
Question savedQuestion1 = questionRepository.save(question1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void updateById() {
new QuestionCreateRequest(
newQuestion.getQuestionType().name(),
newQuestion.getContent(),
newQuestion.getDescription(),
List.of(new ChoiceCreateRequest(
newChoice.getContent(),
newChoice.getSequence()
Expand All @@ -74,6 +75,7 @@ void updateById() {
() -> assertThat(actualQuestions).hasSize(1),
() -> assertThat(actualQuestion.getQuestionType()).isEqualTo(newQuestion.getQuestionType()),
() -> assertThat(actualQuestion.getContent()).isEqualTo(newQuestion.getContent()),
() -> assertThat(actualQuestion.getDescription()).isEqualTo(newQuestion.getDescription()),
() -> assertThat(actualQuestion.getSequence()).isEqualTo(newQuestion.getSequence()),
() -> assertThat(actualQuestion.isRequired()).isEqualTo(newQuestion.isRequired()),

Expand All @@ -99,6 +101,7 @@ void updateByTsid() {
new QuestionCreateRequest(
newQuestion.getQuestionType().name(),
newQuestion.getContent(),
newQuestion.getDescription(),
List.of(new ChoiceCreateRequest(
newChoice.getContent(),
newChoice.getSequence()
Expand All @@ -119,6 +122,7 @@ void updateByTsid() {
() -> assertThat(actualQuestions).hasSize(1),
() -> assertThat(actualQuestion.getQuestionType()).isEqualTo(newQuestion.getQuestionType()),
() -> assertThat(actualQuestion.getContent()).isEqualTo(newQuestion.getContent()),
() -> assertThat(actualQuestion.getDescription()).isEqualTo(newQuestion.getDescription()),
() -> assertThat(actualQuestion.getSequence()).isEqualTo(newQuestion.getSequence()),
() -> assertThat(actualQuestion.isRequired()).isEqualTo(newQuestion.isRequired()),

Expand All @@ -143,6 +147,7 @@ void update_ApplyFormInProgress() {
new QuestionCreateRequest(
newQuestion.getQuestionType().name(),
newQuestion.getContent(),
newQuestion.getDescription(),
List.of(),
newQuestion.getSequence(),
newQuestion.isRequired()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void create() {
QuestionCreateRequest request = new QuestionCreateRequest(
question1.getQuestionType().toString(),
question1.getContent(),
question1.getDescription(),
List.of(),
0,
question1.isRequired()
Expand Down Expand Up @@ -96,7 +97,8 @@ void toQuestionResponse(Question expectedQuestion, QuestionResponse actualRespon
() -> assertThat(actualResponse.id()).isEqualTo(expectedQuestion.getId()),
() -> assertThat(actualResponse.orderIndex()).isEqualTo(expectedQuestion.getSequence()),
() -> assertThat(actualResponse.type()).isEqualTo(expectedQuestion.getQuestionType().toString()),
() -> assertThat(actualResponse.content()).isEqualTo(expectedQuestion.getContent())
() -> assertThat(actualResponse.content()).isEqualTo(expectedQuestion.getContent()),
() -> assertThat(actualResponse.description()).isEqualTo(expectedQuestion.getDescription())
);
}

Expand Down
Loading

0 comments on commit 4a124d4

Please sign in to comment.