-
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
…enge-info-list modify - 완료된 챌린지 정보를 리스트로 보내도록 수정
- Loading branch information
Showing
16 changed files
with
165 additions
and
125 deletions.
There are no files selected for viewing
8 changes: 0 additions & 8 deletions
8
src/main/java/sopt/org/hmh/domain/app/dto/request/AppArrayUsageTimeRequest.java
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
src/main/java/sopt/org/hmh/domain/app/service/AppService.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,46 @@ | ||
package sopt.org.hmh.domain.app.service; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import sopt.org.hmh.domain.app.domain.AppWithGoalTime; | ||
import sopt.org.hmh.domain.app.domain.AppWithUsageGoalTime; | ||
import sopt.org.hmh.domain.app.domain.exception.AppError; | ||
import sopt.org.hmh.domain.app.domain.exception.AppException; | ||
import sopt.org.hmh.domain.app.dto.request.AppUsageTimeRequest; | ||
import sopt.org.hmh.domain.app.repository.AppWithUsageGoalTimeRepository; | ||
import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class AppService { | ||
|
||
private final AppWithUsageGoalTimeRepository appWithUsageGoalTimeRepository; | ||
|
||
public void addAppForHistory(List<AppWithGoalTime> currentChallengeApps, List<AppUsageTimeRequest> apps, | ||
DailyChallenge dailyChallenge, String os) { | ||
appWithUsageGoalTimeRepository.saveAll(supplementAdditionalInfo(currentChallengeApps, apps, dailyChallenge, os)); | ||
} | ||
|
||
private List<AppWithUsageGoalTime> supplementAdditionalInfo(List<AppWithGoalTime> currentChallengeApps, | ||
List<AppUsageTimeRequest> apps, DailyChallenge dailyChallenge, String os) { | ||
return apps.stream().map(app -> AppWithUsageGoalTime.builder() | ||
.goalTime(this.getGoalTime(currentChallengeApps, app.appCode())) | ||
.appCode(app.appCode()) | ||
.dailyChallenge(dailyChallenge) | ||
.os(os) | ||
.usageTime(app.usageTime()) | ||
.build() | ||
).toList(); | ||
} | ||
|
||
private Long getGoalTime(List<AppWithGoalTime> currentChallengeApps, String appCode) { | ||
return currentChallengeApps.stream() | ||
.filter(currentChallengeApp -> currentChallengeApp.getAppCode().equals(appCode)) | ||
.findFirst() | ||
.map(AppWithGoalTime::getGoalTime) | ||
.orElseThrow(() -> new AppException(AppError.APP_NOT_FOUND)); | ||
} | ||
} |
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
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
9 changes: 9 additions & 0 deletions
9
...ava/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeListRequest.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,9 @@ | ||
package sopt.org.hmh.domain.dailychallenge.dto.request; | ||
|
||
import java.util.List; | ||
|
||
public record FinishedDailyChallengeListRequest( | ||
List<FinishedDailyChallengeRequest> finishedDailyChallenges | ||
) { | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...in/java/sopt/org/hmh/domain/dailychallenge/dto/request/FinishedDailyChallengeRequest.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,11 @@ | ||
package sopt.org.hmh.domain.dailychallenge.dto.request; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import sopt.org.hmh.domain.app.dto.request.AppUsageTimeRequest; | ||
|
||
public record FinishedDailyChallengeRequest( | ||
LocalDate challengeDate, | ||
List<AppUsageTimeRequest> apps | ||
) { | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.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,33 @@ | ||
package sopt.org.hmh.domain.dailychallenge.service; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import sopt.org.hmh.domain.app.domain.AppWithGoalTime; | ||
import sopt.org.hmh.domain.app.service.AppService; | ||
import sopt.org.hmh.domain.challenge.service.ChallengeService; | ||
import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge; | ||
import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeListRequest; | ||
import sopt.org.hmh.domain.user.service.UserService; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class DailyChallengeFacade { | ||
|
||
private final DailyChallengeService dailyChallengeService; | ||
private final AppService appService; | ||
private final ChallengeService challengeService; | ||
private final UserService userService; | ||
|
||
public void addFinishedDailyChallengeHistory(Long userId, FinishedDailyChallengeListRequest requests, String os) { | ||
requests.finishedDailyChallenges().forEach(request -> { | ||
DailyChallenge dailyChallenge = dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(request.challengeDate(), userId); | ||
dailyChallengeService.changeStatusByCurrentStatus(dailyChallenge); | ||
Long currentChallengeId = userService.getCurrentChallengeIdByUserId(userId); | ||
List<AppWithGoalTime> currentChallengeApps = challengeService.getCurrentChallengeAppWithGoalTimeByChallengeId(currentChallengeId); | ||
appService.addAppForHistory(currentChallengeApps, request.apps(), dailyChallenge, os); | ||
}); | ||
} | ||
} |
Oops, something went wrong.