From 95ffeb7d8d73b5e0639537ea838572d212865e2f Mon Sep 17 00:00:00 2001 From: nahyeon99 Date: Tue, 6 Aug 2024 22:35:52 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=8B=A4=EC=A4=91=20=EC=84=9C?= =?UTF-8?q?=EC=88=A0=ED=98=95=20=EC=84=A0=ED=83=9D=20=EC=9C=A0=ED=98=95=20?= =?UTF-8?q?=EC=98=B5=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../moring/question/application/QuestionService.java | 1 + .../sambad/moring/question/domain/Question.java | 12 +++++------- .../sambad/moring/question/domain/QuestionType.java | 11 +---------- .../presentation/request/QuestionRequest.java | 9 +++++++-- 4 files changed, 14 insertions(+), 19 deletions(-) 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 - ) { }