Skip to content

Commit

Permalink
feat: 질문별 답변 조회 응답에 optionName 추가(#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
eun-seong committed Mar 19, 2024
1 parent 3c6e49b commit b6ea8f7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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
@@ -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 b6ea8f7

Please sign in to comment.