Skip to content

Commit

Permalink
Merge pull request #116 from dnd-side-project/dev
Browse files Browse the repository at this point in the history
release v0.2.2
  • Loading branch information
eun-seong authored Mar 7, 2024
2 parents 1efde8f + 920a972 commit 0cb01c5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ public static RatioStatistic create(Question question) {

@Override
public void updateStatistic(Answer answer) {
if (answer.getType().isManual()) {
return;
}
increaseTotalCount();

Question question = answer.getQuestion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface SurveyRepository extends MongoRepository<Survey, String> {
Page<Survey> findBySender(User sender, Pageable pageable);
Page<Survey> findByOwnerAndPeriod(User owner, Period period, Pageable pageable);
Page<Survey> findByOwnerAndRelation(User owner, Relation relation, Pageable pageable);
Page<Survey> findBySenderAndPeriod(User sender, Period period, Pageable pageable);
Page<Survey> findBySenderAndRelation(User sender, Relation relation, Pageable pageable);
}
19 changes: 15 additions & 4 deletions src/main/java/com/dnd/namuiwiki/domain/survey/SurveyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ public PageableDto<ReceivedSurveyDto> getReceivedSurveys(TokenUserInfoDto tokenU
}

public PageableDto<SentSurveyDto> getSentSurveys(TokenUserInfoDto tokenUserInfoDto, Period period, Relation relation, int pageNo, int pageSize) {
User user = getUserByWikiId(tokenUserInfoDto.getWikiId());
validateFilter(period, relation);
User sender = getUserByWikiId(tokenUserInfoDto.getWikiId());

Sort sort = Sort.by(Sort.Direction.DESC, "createdAt");
Pageable pageable = PageRequest.of(pageNo, pageSize, sort);
Page<SentSurveyDto> surveys = surveyRepository.findBySender(user, pageable)
Page<SentSurveyDto> surveys = getSentSurveysByFilter(period, relation, sender, pageable)
.map(SentSurveyDto::from);
return PageableDto.create(surveys);
}
Expand All @@ -130,7 +131,7 @@ public GetAnswersByQuestionResponse getAnswersByQuestion(String wikiId, String q

Sort sort = Sort.by(Sort.Direction.DESC, "createdAt");
Pageable pageable = PageRequest.of(pageNo, pageSize, sort);
Page<Survey> surveys = getSurveysByFilter(period, relation, owner, pageable);
Page<Survey> surveys = getReceivedSurveysByFilter(period, relation, owner, pageable);
var answers = surveys.map(survey -> {
var answerOfQuestion = survey.getAnswers().stream()
.filter(answer -> answer.getQuestion().getId().equals(questionId))
Expand All @@ -155,7 +156,17 @@ private void validateFilter(Period period, Relation relation) {
}
}

private Page<Survey> getSurveysByFilter(Period period, Relation relation, User owner, Pageable pageable) {
private Page<Survey> getSentSurveysByFilter(Period period, Relation relation, User sender, Pageable pageable) {
if (!period.isTotal()) {
return surveyRepository.findBySenderAndPeriod(sender, period, pageable);
}
if (!relation.isTotal()) {
return surveyRepository.findBySenderAndRelation(sender, relation, pageable);
}
return surveyRepository.findBySender(sender, pageable);
}

private Page<Survey> getReceivedSurveysByFilter(Period period, Relation relation, User owner, Pageable pageable) {
if (!period.isTotal()) {
return surveyRepository.findByOwnerAndPeriod(owner, period, pageable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.dnd.namuiwiki.domain.survey.model.entity.Survey;
import com.dnd.namuiwiki.domain.survey.type.Period;
import com.dnd.namuiwiki.domain.survey.type.Relation;
import com.dnd.namuiwiki.domain.user.entity.User;
import lombok.AllArgsConstructor;
import lombok.Getter;

Expand All @@ -22,7 +23,7 @@ public static SentSurveyDto from(Survey survey) {
survey.getId(),
survey.getRelation(),
survey.getPeriod(),
survey.getSenderName(),
survey.getOwner().getNickname(),
survey.getWrittenAt()
);
}
Expand Down

0 comments on commit 0cb01c5

Please sign in to comment.