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

[SAMBAD-226] 다중 서술형 선택 유형 옵션 추가 #88

Merged
merged 1 commit into from
Aug 6, 2024
Merged
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
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

) {
}
Loading