Skip to content

Commit

Permalink
Merge pull request #135 from dnd-side-project/staging
Browse files Browse the repository at this point in the history
release v0.2.6
  • Loading branch information
eun-seong authored Mar 19, 2024
2 parents 3b91a6c + 094ec5f commit 66ad20a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Option extends BaseTimeEntity {
private String id;
private Object value;
private String text;
private String name;
private int order;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public GetAnswersByQuestionResponse getAnswersByQuestion(String wikiId, String q
.createdAt(survey.getWrittenAt())
.answer(convertAnswerToText(question, answerOfQuestion))
.reason(answerOfQuestion.getReason())
.optionName(question, answerOfQuestion)
.build();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.dnd.namuiwiki.domain.question.type.QuestionName;
import com.dnd.namuiwiki.domain.survey.model.entity.Answer;
import com.dnd.namuiwiki.domain.survey.model.entity.Survey;
import com.dnd.namuiwiki.domain.survey.type.AnswerType;
import com.dnd.namuiwiki.domain.survey.type.Period;
import com.dnd.namuiwiki.domain.survey.type.Relation;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -36,15 +35,19 @@ private static class SingleQuestionAndAnswer {
private Object value;
private String reason;
private QuestionName questionName;
private String optionName;

static SingleQuestionAndAnswer from(Question question, Answer surveyAnswer) {
if (surveyAnswer.getType().equals(AnswerType.MANUAL)) {
String optionName = getOptionName(question, surveyAnswer);

if (surveyAnswer.getType().isManual()) {
return new SingleQuestionAndAnswer(
question.getTitle(),
surveyAnswer.getAnswer().toString(),
surveyAnswer.getAnswer(),
surveyAnswer.getReason(),
question.getName()
question.getName(),
optionName
);
}
Option option = question.getOption(surveyAnswer.getAnswer().toString())
Expand All @@ -54,9 +57,29 @@ static SingleQuestionAndAnswer from(Question question, Answer surveyAnswer) {
option.getText(),
option.getValue(),
surveyAnswer.getReason(),
question.getName()
question.getName(),
optionName
);
}

private static String getOptionName(Question question, Answer surveyAnswer) {
String optionName = null;

if (question.getType().isChoiceType()) {
if (surveyAnswer.getType().isOption()) {
optionName = question.getOption(surveyAnswer.getAnswer().toString())
.orElseThrow(() -> new ApplicationErrorException(ApplicationErrorType.INVALID_OPTION_ID))
.getName();
} else {
optionName = question.getOptions().values().stream()
.filter(option -> option.getName().contains("MANUAL"))
.findFirst()
.orElseThrow(() -> new ApplicationErrorException(ApplicationErrorType.INVALID_OPTION_ID))
.getName();
}
}
return optionName;
}
}

public static GetSurveyResponse from(Survey survey, List<Question> questions) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.dnd.namuiwiki.domain.survey.model.dto;

import com.dnd.namuiwiki.common.exception.ApplicationErrorException;
import com.dnd.namuiwiki.common.exception.ApplicationErrorType;
import com.dnd.namuiwiki.domain.question.entity.Question;
import com.dnd.namuiwiki.domain.survey.model.entity.Answer;
import com.dnd.namuiwiki.domain.survey.type.Period;
import com.dnd.namuiwiki.domain.survey.type.Relation;
import lombok.Builder;
Expand All @@ -16,4 +20,28 @@ public class SingleAnswerWithSurveyDetailDto {
private LocalDateTime createdAt;
private String answer;
private String reason;
private String optionName;

public static class SingleAnswerWithSurveyDetailDtoBuilder {
public SingleAnswerWithSurveyDetailDtoBuilder optionName(Question question, Answer surveyAnswer) {
String optionName = null;

if (question.getType().isChoiceType()) {
if (surveyAnswer.getType().isOption()) {
optionName = question.getOption(surveyAnswer.getAnswer().toString())
.orElseThrow(() -> new ApplicationErrorException(ApplicationErrorType.INVALID_OPTION_ID))
.getName();
} else {
optionName = question.getOptions().values().stream()
.filter(option -> option.getName().contains("MANUAL"))
.findFirst()
.orElseThrow(() -> new ApplicationErrorException(ApplicationErrorType.INVALID_OPTION_ID))
.getName();
}
}
this.optionName = optionName;
return this;
}
}

}

0 comments on commit 66ad20a

Please sign in to comment.