Skip to content

Commit

Permalink
refactor: 다중 서술형 선택 유형 옵션 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
nahyeon99 committed Aug 6, 2024
1 parent 791bdf1 commit 95ffeb7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void saveQuestion(QuestionRequest questionRequest) {
Question question = Question.builder()
.title(questionRequest.title())
.questionImageFile(image)
.questionType(questionRequest.questionType())
.answerContents(questionRequest.answerContents())
.build();
questionRepository.save(question);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public class Question extends BaseTimeEntity {

private static final int MIN_ANSWER_COUNT = 2;
private static final int MAX_ANSWER_COUNT = 16;
private static final int MAX_ANSWER_COUNT = 9;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -56,9 +56,10 @@ public class Question extends BaseTimeEntity {
private List<Answer> answers = new ArrayList<>();

@Builder
public Question(String title, FileEntity questionImageFile, List<String> answerContents) {
public Question(String title, FileEntity questionImageFile, QuestionType questionType,
List<String> answerContents) {
validateAnswerCount(answerContents);
this.questionType = QuestionType.getQuestionType(answerContents.size());
this.questionType = questionType;
this.title = title;
this.questionImageFile = questionImageFile;

Expand All @@ -83,10 +84,7 @@ public String getQuestionImageUrl() {
}

public QuestionType getQuestionType() {
if (questionType != null)
return questionType;

return QuestionType.getQuestionType(answers.size());
return questionType;
}

private void validateAnswerCount(List<String> answerContents) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
package org.depromeet.sambad.moring.question.domain;

public enum QuestionType {
SINGLE_CHOICE, MULTIPLE_CHOICE;

private static final int SINGLE_CHOICE_ANSWER_COUNT = 2;

public static QuestionType getQuestionType(int answerSize) {
if (answerSize <= SINGLE_CHOICE_ANSWER_COUNT) {
return SINGLE_CHOICE;
}
return MULTIPLE_CHOICE;
}
SINGLE_CHOICE, MULTIPLE_SHORT_CHOICE, MULTIPLE_DESCRIPTIVE_CHOICE;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.depromeet.sambad.moring.question.presentation.request;

import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.*;

import java.util.List;

import org.depromeet.sambad.moring.question.domain.QuestionType;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand All @@ -17,13 +19,16 @@ public record QuestionRequest(
@NotNull
String questionImageUrl,

@Schema(description = "질문 유형", example = "MULTIPLE_SHORT_CHOICE", requiredMode = REQUIRED)
@NotNull
QuestionType questionType,

@Schema(
description = "답변 내용",
example = "[\"답변1 예시입니다.\", \"답변2 예시입니다.\", \"답변3 예시입니다.\"]",
requiredMode = REQUIRED
)
@NotNull
List<String> answerContents

) {
}

0 comments on commit 95ffeb7

Please sign in to comment.