diff --git a/src/main/java/com/dnd/namuiwiki/domain/survey/SurveyService.java b/src/main/java/com/dnd/namuiwiki/domain/survey/SurveyService.java index e38e5b0..4dd178e 100644 --- a/src/main/java/com/dnd/namuiwiki/domain/survey/SurveyService.java +++ b/src/main/java/com/dnd/namuiwiki/domain/survey/SurveyService.java @@ -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(); }); diff --git a/src/main/java/com/dnd/namuiwiki/domain/survey/model/dto/SingleAnswerWithSurveyDetailDto.java b/src/main/java/com/dnd/namuiwiki/domain/survey/model/dto/SingleAnswerWithSurveyDetailDto.java index 8c9ed92..7581ab8 100644 --- a/src/main/java/com/dnd/namuiwiki/domain/survey/model/dto/SingleAnswerWithSurveyDetailDto.java +++ b/src/main/java/com/dnd/namuiwiki/domain/survey/model/dto/SingleAnswerWithSurveyDetailDto.java @@ -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; @@ -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; + } + } + }