Skip to content

Commit

Permalink
Merge pull request #25 from Ong-gi-Jong-gi/feature/TSK-44/recap-ranking
Browse files Browse the repository at this point in the history
fix: get challenge modify
  • Loading branch information
dongyeoppp authored Jul 9, 2024
2 parents f5f4c85 + 6b8dc69 commit 083e9f8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public ApiResponse<NormalChallengeDto> getNormalChallenge(@RequestParam("challen
Member member = memberService.findMemberByLoginId(); // 로그인한 멤버 찾기
boolean isComplete = answerService.findIsCompleteAnswer(challenge, member);
Long challengeDate = answerService.findDateByChallengeMember(challenge);
List<Answer> answers = answerService.findAnswerByChallenge(challenge);
List<Answer> answers = answerService.findAnswerByChallengeandFamily(challenge, member);

NormalChallengeDto normalChallengeDto = new NormalChallengeDto(challenge, isComplete, challengeDate, answers);

Expand Down Expand Up @@ -123,7 +123,7 @@ public ApiResponse<GroupChallengeDto> getGroupChallenge(@RequestParam("challenge
Long challengeDate = answerService.findDateByChallengeMember(challenge);
Member member = memberService.findMemberByLoginId(); // 로그인한 멤버 찾기
boolean isComplete = answerService.findIsCompleteAnswer(challenge, member);
List<Answer> allAnswers = answerService.findAnswersByChallenges(challenge); // 특정 그룹 챌린지에 매핑된 answer list 찾기
List<Answer> allAnswers = answerService.findAnswersByChallenges(challenge, member); // 특정 그룹 챌린지에 매핑된 answer list 찾기

GroupChallengeDto groupChallengeDto = new GroupChallengeDto(challenge, challengeDate, isComplete, allAnswers);
return new ApiResponse<>("success", "Challenge retrieved successfully", groupChallengeDto);
Expand Down Expand Up @@ -153,7 +153,7 @@ public ApiResponse<PhotoChallengeDto> getPhotoChallenge(@RequestParam("challenge

boolean isComplete = answerService.findIsCompleteAnswer(challenge, member);
Long challengeDate = answerService.findDateByChallengeMember(challenge);
List<Answer> answers = answerService.findAnswerByChallenge(challenge);
List<Answer> answers = answerService.findAnswerByChallengeandFamily(challenge, member);

PhotoChallengeDto photoChallengeDto = new PhotoChallengeDto(challenge, isComplete, challengeDate, answers);

Expand Down Expand Up @@ -328,7 +328,7 @@ public ApiResponse<VoiceChallengeDto> getVoiceChallenge(@RequestParam("challenge
Member member = memberService.findMemberByLoginId(); // 로그인한 멤버 찾기
boolean isComplete = answerService.findIsCompleteAnswer(challenge, member);
Long challengeDate = answerService.findDateByChallengeMember(challenge);
List<Answer> answers = answerService.findAnswerByChallenge(challenge);
List<Answer> answers = answerService.findAnswerByChallengeandFamily(challenge, member);

VoiceChallengeDto voiceChallengeDto = new VoiceChallengeDto(challenge, isComplete, challengeDate, answers);

Expand Down
25 changes: 23 additions & 2 deletions src/main/java/ongjong/namanmoo/service/AnswerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Slf4j
@Service
Expand Down Expand Up @@ -141,6 +143,19 @@ public List<Answer> findAnswerByChallenge(Challenge challenge){
return answerRepository.findByChallenge(challenge);
}

// 해당 챌린지와 매핑된 답변 중 로그인 하고 있는 맴버 가족의 답변리스트만을 반환
@Transactional(readOnly = true)
public List<Answer> findAnswerByChallengeandFamily(Challenge challenge, Member member){
Family family = member.getFamily();
// answers 리스트를 순회하면서 answer의 memberid값을 member를 구하고 그 member가 가지고 있는 familyid가 위에서 구한 familyid와 다를 경우 answers에서 제거해야해
return answerRepository.findByChallenge(challenge).stream()
.filter(answer -> {
Member answerMember = answer.getMember();
return answerMember != null && family.getFamilyId().equals(answerMember.getFamily().getFamilyId());
})
.collect(Collectors.toList());
}

// 가족 구성원들의 답변 유무 검사
@Transactional(readOnly = true)
public boolean isAnyAnswerComplete(Challenge challenge, Family family) {
Expand Down Expand Up @@ -226,14 +241,20 @@ public void offBalloon(Long challengeDate) throws Exception {
}

@Transactional(readOnly = true)
public List<Answer> findAnswersByChallenges(Challenge challenge) { // 특정 그룹 챌린지에 매핑된 answer list 찾기
public List<Answer> findAnswersByChallenges(Challenge challenge, Member member) { // 특정 그룹 챌린지에 매핑된 answer list 찾기
List<Challenge> groupChallenges = challengeService.findChallengesByChallengeNum(challenge.getChallengeNum()); // challengeNum이 같은 챌린지 찾기
Family family = member.getFamily();
List<Answer> allAnswers = new ArrayList<>(); // 해당 그룹질문으로 묶인 answer 가져오기
for (Challenge relatedChallenge : groupChallenges) {
List<Answer> answers = findAnswerByChallenge(relatedChallenge);
allAnswers.addAll(answers);
}
return allAnswers;
return allAnswers.stream()
.filter(answer -> {
Member answerMember = answer.getMember();
return answerMember != null && family.getFamilyId().equals(answerMember.getFamily().getFamilyId());
})
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Long findCurrentChallengeNum(Long familyId, Long challengeDate) { /
for (Lucky lucky : luckies) {
if (lucky.isRunning()) {
DateUtil dateUtil = DateUtil.getInstance();
return dateUtil.getDateDifference(lucky.getChallengeStartDate(), dateUtil.timestampToString(challengeDate))+1; // 현재 진행되어야할 challenge를 반환
return dateUtil.getDateDifference(lucky.getChallengeStartDate(), dateUtil.timestampToString(challengeDate)); // 현재 진행되어야할 challenge를 반환
}
}
return null;
Expand Down

0 comments on commit 083e9f8

Please sign in to comment.