Skip to content

Commit

Permalink
feat: 질문 조회시 공통 질문 여부 boolean 값으로 반환 되도록 추가 #3
Browse files Browse the repository at this point in the history
  • Loading branch information
623nana committed Aug 7, 2021
1 parent 5bd8b9c commit 5b3c999
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/nexters/covid/base/Constant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.nexters.covid.base;

public class Constant {

public static final Long COMMON_SEND_OPTION_ID = 3L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import static org.springframework.beans.BeanUtils.copyProperties;

import com.nexters.covid.base.Constant;
import com.nexters.covid.letter.domain.question.Question;
import com.nexters.covid.letter.domain.sendoption.SendOption;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -11,10 +13,15 @@
public class QuestionResponse {

private Long id;

private String text;
private boolean commonOptionId;

public QuestionResponse(Question source) {
copyProperties(source, this);
this.commonOptionId = isCommonOptionId(source.getSendOption());
}

private boolean isCommonOptionId(SendOption sendOption) {
return sendOption.getId().equals(Constant.COMMON_SEND_OPTION_ID);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.nexters.covid.letter.service;

import com.nexters.covid.base.Constant;
import com.nexters.covid.letter.api.dto.LetterRequest;
import com.nexters.covid.letter.api.dto.LetterResponse;
import com.nexters.covid.letter.api.dto.OptionResponse;
Expand All @@ -20,8 +21,6 @@
@Service
public class LetterService {

private static final Long COMMON_SEND_OPTION_ID = 3L;

private final LetterRepository letterRepository;
private final SendOptionRepository sendOptionRepository;
private final QuestionRepository questionRepository;
Expand All @@ -46,7 +45,7 @@ public List<OptionResponse> findAllOptions() {
@Transactional(readOnly = true)
public List<QuestionResponse> findQuestionsByOptionId(Long optionId) {
return questionRepository
.findQuestionsBySendOptionIdEqualsOrSendOptionIdEquals(optionId, COMMON_SEND_OPTION_ID)
.findQuestionsBySendOptionIdEqualsOrSendOptionIdEquals(optionId, Constant.COMMON_SEND_OPTION_ID)
.stream()
.map(QuestionResponse::new)
.collect(Collectors.toList());
Expand Down

0 comments on commit 5b3c999

Please sign in to comment.