Skip to content

Commit

Permalink
fix: 편지 상세 조회시 질문 텍스트 보내주도록 수정 #3
Browse files Browse the repository at this point in the history
  • Loading branch information
623nana committed Aug 16, 2021
1 parent 61da059 commit e3ca1e7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.nexters.covid.letter.domain.Letter;
import com.nexters.covid.letter.domain.State;
import com.nexters.covid.letter.domain.Sticker;
import com.nexters.covid.letter.domain.question.Question;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -26,6 +27,8 @@ public class LetterResponse {

private Long questionId;

private String questionText;

private String encryptedId;

private String sendOptionText;
Expand All @@ -42,6 +45,11 @@ public LetterResponse(Letter source, String sendOptionText) {
this.sendOptionText = sendOptionText;
}

public LetterResponse(Letter source, Question question) {
this(source);
this.questionText = question.getText();
}

private String decodeContents(String contents) {
return new String(decodeBase64(contents));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
public interface QuestionRepository extends JpaRepository<Question, Long> {

List<Question> findQuestionsBySendOptionIdEqualsOrSendOptionIdEquals(Long optionId, Long commonOptionId);

Question findQuestionById(Long questionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.nexters.covid.letter.api.dto.QuestionResponse;
import com.nexters.covid.letter.domain.Letter;
import com.nexters.covid.letter.domain.LetterRepository;
import com.nexters.covid.letter.domain.question.Question;
import com.nexters.covid.letter.domain.question.QuestionRepository;
import com.nexters.covid.letter.domain.sendoption.SendOption;
import com.nexters.covid.letter.domain.sendoption.SendOptionRepository;
Expand Down Expand Up @@ -76,6 +77,9 @@ public LetterResponse saveLetter(LetterRequest letterRequest) {
public LetterResponse findLetterByEncryptedId(String encryptedId) {
Letter letter = letterRepository.findLetterByEncryptedId(encryptedId)
.orElseThrow(() -> new IllegalArgumentException("해당 ID의 편지가 없습니다."));
return new LetterResponse(letter);

Question question = questionRepository.findQuestionById(letter.getQuestionId());

return new LetterResponse(letter, question);
}
}

0 comments on commit e3ca1e7

Please sign in to comment.