-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modify - 일별챌린지 결과 전송 후 챌린지의 변경된 상태값들을 반환하도록 수정 #184
Changes from 5 commits
f999db4
445cb02
39006e5
7189932
a016925
d3fa095
1886a83
b4f96b8
22ab912
2ca0d57
948da00
62c0b7a
e78100d
8377bea
4fbb30f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package sopt.org.hmh.domain.dailychallenge.dto.response; | ||
|
||
import sopt.org.hmh.domain.dailychallenge.domain.Status; | ||
|
||
import java.util.List; | ||
|
||
public record ChallengeStatusesResponse( | ||
List<Status> statuses | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import org.springframework.transaction.annotation.Transactional; | ||
import sopt.org.hmh.domain.app.domain.ChallengeApp; | ||
import sopt.org.hmh.domain.app.service.HistoryAppService; | ||
import sopt.org.hmh.domain.challenge.domain.Challenge; | ||
import sopt.org.hmh.domain.challenge.service.ChallengeService; | ||
import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge; | ||
import sopt.org.hmh.domain.dailychallenge.domain.Status; | ||
|
@@ -23,27 +24,31 @@ public class DailyChallengeFacade { | |
private final UserService userService; | ||
|
||
@Transactional | ||
public void addFinishedDailyChallengeHistory(Long userId, FinishedDailyChallengeListRequest requests, String os) { | ||
Long currentChallengeId = userService.getCurrentChallengeIdByUserId(userId); | ||
List<ChallengeApp> currentChallengeApps = | ||
challengeService.getCurrentChallengeAppByChallengeId(currentChallengeId); | ||
public List<Status> addFinishedDailyChallengeHistory(Long userId, FinishedDailyChallengeListRequest requests, String os) { | ||
Challenge challenge = challengeService.findByIdOrElseThrow(userService.getCurrentChallengeIdByUserId(userId)); | ||
|
||
requests.finishedDailyChallenges().forEach(request -> { | ||
DailyChallenge dailyChallenge = | ||
dailyChallengeService.findDailyChallengeByChallengeIdAndChallengePeriodIndex( | ||
currentChallengeId, request.challengePeriodIndex()); | ||
challenge.getId(), request.challengePeriodIndex()); | ||
dailyChallengeService.changeStatusByCurrentStatus(dailyChallenge); | ||
historyAppService.addHistoryApp(currentChallengeApps, request.apps(), dailyChallenge, os); | ||
historyAppService.addHistoryApp(challenge.getApps(), request.apps(), dailyChallenge, os); | ||
}); | ||
|
||
return challenge.getHistoryDailyChallenges() | ||
.stream() | ||
.map(DailyChallenge::getStatus) | ||
.toList(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분은 아래 코드와도 중복된 부분이니 메서드로 중복을 제거해주는 것도 좋을 것 같아요 |
||
} | ||
|
||
@Transactional | ||
public void changeDailyChallengeStatusByIsSuccess(Long userId, FinishedDailyChallengeStatusListRequest requests) { | ||
Long currentChallengeId = userService.getCurrentChallengeIdByUserId(userId); | ||
public List<Status> changeDailyChallengeStatusByIsSuccess(Long userId, FinishedDailyChallengeStatusListRequest requests) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기 requests도... 부탁드립니다 |
||
Challenge challenge = challengeService.findByIdOrElseThrow(userService.getCurrentChallengeIdByUserId(userId)); | ||
|
||
requests.finishedDailyChallenges().forEach(request -> { | ||
DailyChallenge dailyChallenge = | ||
dailyChallengeService.findDailyChallengeByChallengeIdAndChallengePeriodIndex( | ||
currentChallengeId, request.challengePeriodIndex()); | ||
challenge.getId(), request.challengePeriodIndex()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 레포지토리 사용을 주민님은 현재 변경한 코드를 봤을 때, 챌린지를 이미 찾았다면, 그 Challenge 객체의 dailyChallenge에서 periodIndex를 계산하는 것이 더 쿼리를 줄일 수 있는 방법일 것 같은데 어떻게 생각하시나요? 물론 challenge를 찾고 dailyChallenge를 가져올 때 JPA에서 알아서 지연로딩으로 가져와서 성능상에는 똑같을 지도 모르긴 하는데... 혹시 고려하시고 한 것인지 궁금합니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 가능하시다면 쿼리 어떻게 나가나 한 번 봐주세요..! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 마지막에 challenge의 상태리스트를 반환할 때 재사용하려고 |
||
if (request.isSuccess()) { | ||
dailyChallengeService.validateDailyChallengeStatus(dailyChallenge.getStatus(), List.of(Status.NONE)); | ||
dailyChallenge.changeStatus(Status.UNEARNED); | ||
|
@@ -53,5 +58,10 @@ public void changeDailyChallengeStatusByIsSuccess(Long userId, FinishedDailyChal | |
dailyChallenge.changeStatus(Status.FAILURE); | ||
} | ||
}); | ||
|
||
return challenge.getHistoryDailyChallenges() | ||
.stream() | ||
.map(DailyChallenge::getStatus) | ||
.toList(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 한건거 같긴한데... FinishedDailyChallengeListRequest requests 에서 변수명에 s가 들어가는 것이 찜찜해서 혹시 request로 변경 가능할까요?
그러려면 스트림에서 사용한 request 변수의 네이밍을 challengeRequest로 바꿔주면 좋을 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아래 메서드도 s가 들어가있던데 한 번 부탁드립니다..!