-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
�feat - 달성현황 정보 불러오기
- Loading branch information
Showing
10 changed files
with
108 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/sopt/org/HMH/domain/challenge/dto/response/ChallengeResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package sopt.org.HMH.domain.challenge.dto.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.val; | ||
import sopt.org.HMH.domain.app.dto.response.AppGoalTimeResponse; | ||
import sopt.org.HMH.domain.challenge.domain.Challenge; | ||
import sopt.org.HMH.domain.dailychallenge.domain.Status; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
public record ChallengeResponse( | ||
Integer period, | ||
List<Status> statuses, | ||
Integer todayIndex, | ||
Long goalTime, | ||
List<AppGoalTimeResponse> apps | ||
) { | ||
public static ChallengeResponse of(Challenge challenge) { | ||
val dailyChallenges = challenge.getDailyChallenges(); | ||
|
||
val statuses = new ArrayList<Status>(); | ||
for (val dailyChallenge : dailyChallenges) { | ||
statuses.add(dailyChallenge.getStatus()); | ||
} | ||
|
||
val startDayOfChallenge = challenge.getDailyChallenges().get(0); | ||
val todayIndex = calculateDaysSinceToday(startDayOfChallenge.getCreatedAt()); | ||
val todayDailyChallenge = dailyChallenges.get(todayIndex); | ||
|
||
return ChallengeResponse.builder() | ||
.period(challenge.getPeriod()) | ||
.statuses(statuses) | ||
.todayIndex(todayIndex) | ||
.goalTime(todayDailyChallenge.getGoalTime()) | ||
.apps(todayDailyChallenge.getApps() | ||
.stream() | ||
.map(AppGoalTimeResponse::of) | ||
.toList()) | ||
.build(); | ||
} | ||
|
||
private static Integer calculateDaysSinceToday(LocalDateTime dateToCompare) { | ||
return (int) ChronoUnit.DAYS.between(LocalDateTime.now().toLocalDate(), dateToCompare.toLocalDate()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters