diff --git a/src/main/java/org/depromeet/sambad/moring/question/application/QuestionService.java b/src/main/java/org/depromeet/sambad/moring/question/application/QuestionService.java index d2e2d45d..0b5f2d8f 100644 --- a/src/main/java/org/depromeet/sambad/moring/question/application/QuestionService.java +++ b/src/main/java/org/depromeet/sambad/moring/question/application/QuestionService.java @@ -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); diff --git a/src/main/java/org/depromeet/sambad/moring/question/domain/Question.java b/src/main/java/org/depromeet/sambad/moring/question/domain/Question.java index 366c48ec..3fb3d76b 100644 --- a/src/main/java/org/depromeet/sambad/moring/question/domain/Question.java +++ b/src/main/java/org/depromeet/sambad/moring/question/domain/Question.java @@ -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) @@ -56,9 +56,10 @@ public class Question extends BaseTimeEntity { private List answers = new ArrayList<>(); @Builder - public Question(String title, FileEntity questionImageFile, List answerContents) { + public Question(String title, FileEntity questionImageFile, QuestionType questionType, + List answerContents) { validateAnswerCount(answerContents); - this.questionType = QuestionType.getQuestionType(answerContents.size()); + this.questionType = questionType; this.title = title; this.questionImageFile = questionImageFile; @@ -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 answerContents) { diff --git a/src/main/java/org/depromeet/sambad/moring/question/domain/QuestionType.java b/src/main/java/org/depromeet/sambad/moring/question/domain/QuestionType.java index 75d8eb98..04598f67 100644 --- a/src/main/java/org/depromeet/sambad/moring/question/domain/QuestionType.java +++ b/src/main/java/org/depromeet/sambad/moring/question/domain/QuestionType.java @@ -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; } diff --git a/src/main/java/org/depromeet/sambad/moring/question/presentation/request/QuestionRequest.java b/src/main/java/org/depromeet/sambad/moring/question/presentation/request/QuestionRequest.java index 4b2671a4..c81b4386 100644 --- a/src/main/java/org/depromeet/sambad/moring/question/presentation/request/QuestionRequest.java +++ b/src/main/java/org/depromeet/sambad/moring/question/presentation/request/QuestionRequest.java @@ -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; @@ -17,6 +19,10 @@ public record QuestionRequest( @NotNull String questionImageUrl, + @Schema(description = "질문 유형", example = "MULTIPLE_SHORT_CHOICE", requiredMode = REQUIRED) + @NotNull + QuestionType questionType, + @Schema( description = "답변 내용", example = "[\"답변1 예시입니다.\", \"답변2 예시입니다.\", \"답변3 예시입니다.\"]", @@ -24,6 +30,5 @@ public record QuestionRequest( ) @NotNull List answerContents - ) { }