-
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 - μ±λ¦°μ§ μμ± api μμ
- Loading branch information
Showing
12 changed files
with
112 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ public record AppGoalTimeRequest( | |
String appCode, | ||
Long goalTime | ||
) { | ||
} | ||
} |
5 changes: 0 additions & 5 deletions
5
src/main/java/sopt/org/HMH/domain/app/dto/response/AppGoalTimeResponse.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 |
---|---|---|
@@ -1,12 +1,7 @@ | ||
package sopt.org.HMH.domain.app.dto.response; | ||
|
||
import sopt.org.HMH.domain.app.domain.App; | ||
|
||
public record AppGoalTimeResponse( | ||
String appCode, | ||
Long goalTime | ||
) { | ||
public static AppGoalTimeResponse of(App app) { | ||
return new AppGoalTimeResponse(app.getAppCode(), app.getGoalTime()); | ||
} | ||
} |
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
3 changes: 0 additions & 3 deletions
3
src/main/java/sopt/org/HMH/domain/challenge/dto/request/ChallengeRequest.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
9 changes: 0 additions & 9 deletions
9
src/main/java/sopt/org/HMH/domain/challenge/dto/response/AddChallengeResponse.java
This file was deleted.
Oops, something went wrong.
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
43 changes: 32 additions & 11 deletions
43
src/main/java/sopt/org/HMH/domain/challenge/service/ChallengeService.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 |
---|---|---|
@@ -1,34 +1,55 @@ | ||
package sopt.org.HMH.domain.challenge.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.val; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import sopt.org.HMH.domain.app.dto.request.AppGoalTimeRequest; | ||
import sopt.org.HMH.domain.app.service.AppService; | ||
import sopt.org.HMH.domain.challenge.domain.Challenge; | ||
import sopt.org.HMH.domain.challenge.dto.response.AddChallengeResponse; | ||
import sopt.org.HMH.domain.challenge.dto.response.ChallengeResponse; | ||
import sopt.org.HMH.domain.challenge.repository.ChallengeRepository; | ||
import sopt.org.HMH.domain.dailychallenge.domain.DailyChallenge; | ||
import sopt.org.HMH.domain.dailychallenge.service.DailyChallengeService; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ChallengeService { | ||
|
||
private final ChallengeRepository challengeRepository; | ||
private final DailyChallengeService dailyChallengeService; | ||
private final AppService appService; | ||
|
||
@Transactional | ||
public Challenge addChallenge(Long userId, Integer period, Long goalTime) { | ||
return challengeRepository.save(Challenge.builder() | ||
.period(period) | ||
.goalTime(goalTime) | ||
.userId(userId).build()); | ||
} | ||
|
||
@Transactional | ||
public AddChallengeResponse addChallenge(Long userId, Integer period, Long goalTime) { | ||
Challenge challenge = challengeRepository.save(Challenge.builder() | ||
.period(period) | ||
.goalTime(goalTime) | ||
.userId(userId).build()); | ||
dailyChallengeService.addDailyChallengesForPeriod(challenge, period, goalTime); | ||
return AddChallengeResponse.of(challenge.getId()); | ||
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); | ||
} | ||
|
||
return challenge; | ||
} | ||
|
||
public List<AppGoalTimeRequest> getLastApps(Long userId) { | ||
List<DailyChallenge> lastDailyChallenges = challengeRepository.findFirstByUserIdOrderByCreatedAtDesc(userId).getDailyChallenges(); | ||
List<AppGoalTimeRequest> lastApps = lastDailyChallenges.get(lastDailyChallenges.size()-1) | ||
.getApps() | ||
.stream() | ||
.map(app -> new AppGoalTimeRequest(app.getAppCode(), app.getGoalTime())) | ||
.toList(); | ||
return lastApps; | ||
} | ||
|
||
public ChallengeResponse getChallenge(Long userId, String os) { | ||
val challenge = challengeRepository.findFirstByUserIdOrderByCreatedAtDesc(userId); | ||
return ChallengeResponse.of(challenge, os); | ||
return ChallengeResponse.of(challengeRepository.findFirstByUserIdOrderByCreatedAtDesc(userId), os); | ||
} | ||
} |
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
Oops, something went wrong.