From 0736e4c50ca4117497f3ad99d5f3343e61eda985 Mon Sep 17 00:00:00 2001 From: eun-seong Date: Wed, 20 Mar 2024 00:54:44 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=A7=88=EB=AC=B8=EC=9D=B4=20NUMERIC?= =?UTF-8?q?=20=ED=83=80=EC=9E=85=EC=9D=BC=20=EA=B2=BD=EC=9A=B0,=20?= =?UTF-8?q?=EB=8B=B5=EB=B3=80=EC=9D=84=20=EC=A0=95=EC=88=98=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5(#136)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dnd/namuiwiki/domain/survey/SurveyService.java | 10 +++++++--- .../model/dto/SingleAnswerWithSurveyDetailDto.java | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) 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 4dd178e..9450ad4 100644 --- a/src/main/java/com/dnd/namuiwiki/domain/survey/SurveyService.java +++ b/src/main/java/com/dnd/namuiwiki/domain/survey/SurveyService.java @@ -142,7 +142,7 @@ public GetAnswersByQuestionResponse getAnswersByQuestion(String wikiId, String q .period(survey.getPeriod()) .relation(survey.getRelation()) .createdAt(survey.getWrittenAt()) - .answer(convertAnswerToText(question, answerOfQuestion)) + .answer(convertAnswer(question, answerOfQuestion)) .reason(answerOfQuestion.getReason()) .optionName(question, answerOfQuestion) .build(); @@ -177,12 +177,16 @@ private Page getReceivedSurveysByFilter(Period period, Relation relation return surveyRepository.findByOwner(owner, pageable); } - private String convertAnswerToText(Question question, Answer answer) { + private Object convertAnswer(Question question, Answer answer) { if (answer.getType().equals(AnswerType.MANUAL)) { - return answer.getAnswer().toString(); + return answer.getAnswer(); } + Option option = question.getOption(answer.getAnswer().toString()) .orElseThrow(() -> new ApplicationErrorException(ApplicationErrorType.INVALID_OPTION_ID)); + if (question.getType().isNumericType()) { + return option.getValue(); + } return option.getText(); } 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 7581ab8..00f1454 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 @@ -18,7 +18,7 @@ public class SingleAnswerWithSurveyDetailDto { private Period period; private Relation relation; private LocalDateTime createdAt; - private String answer; + private Object answer; private String reason; private String optionName;