From b6ea8f70d55a23ef09f6e63d7863fd6aa6e2769c Mon Sep 17 00:00:00 2001 From: eun-seong Date: Tue, 19 Mar 2024 23:05:11 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=A7=88=EB=AC=B8=EB=B3=84=20=EB=8B=B5?= =?UTF-8?q?=EB=B3=80=20=EC=A1=B0=ED=9A=8C=20=EC=9D=91=EB=8B=B5=EC=97=90=20?= =?UTF-8?q?optionName=20=EC=B6=94=EA=B0=80(#133)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/survey/SurveyService.java | 1 + .../dto/SingleAnswerWithSurveyDetailDto.java | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) 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 e38e5b05..4dd178e2 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 8c9ed927..7581ab84 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; + } + } + }