Skip to content

Commit

Permalink
feat - #68 챌린지 생성 저번 챌린지가 없는 경우에는 앱목록이 없이 챌린지가 생성되도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jumining committed Jan 17, 2024
1 parent 541cacf commit 1f9f0d6
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sopt.org.HMH.domain.challenge.service;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -13,6 +14,8 @@

import java.util.List;

import static java.util.Objects.nonNull;

@Service
@RequiredArgsConstructor
public class ChallengeService {
Expand All @@ -33,15 +36,18 @@ public Challenge addChallenge(Long userId, Integer period, Long goalTime) {
public Challenge updateChallengeForPeriodWithInfo(Challenge challenge, List<AppGoalTimeRequest> apps, String os) {
for (int count = 0; count < challenge.getPeriod(); count++) {
DailyChallenge dailyChallenge = dailyChallengeService.addDailyChallenge(challenge);
appService.addApps(dailyChallenge, apps, os);
if (nonNull(apps)) {
appService.addApps(dailyChallenge, apps, os);
}
}

return challenge;
}

public List<AppGoalTimeRequest> getLastApps(Long userId) {
List<DailyChallenge> lastDailyChallenges = challengeRepository.findFirstByUserIdOrderByCreatedAtDesc(userId).getDailyChallenges();
List<AppGoalTimeRequest> lastApps = lastDailyChallenges.get(lastDailyChallenges.size()-1)
if (lastDailyChallenges.size() == 0) { return null; }
List<AppGoalTimeRequest> lastApps = lastDailyChallenges.get(lastDailyChallenges.size() - 1)
.getApps()
.stream()
.map(app -> new AppGoalTimeRequest(app.getAppCode(), app.getGoalTime()))
Expand Down

0 comments on commit 1f9f0d6

Please sign in to comment.