Created
October 20, 2023 15:02
-
-
Save johnkil/f31c6d92837c83ea9ede27314cdc932a to your computer and use it in GitHub Desktop.
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
class SyncChallengesProgressUseCase @Inject constructor( | |
private val challengesRepository: ChallengesRepository, | |
private val getStepsFromFitnessApp: GetStepsFromFitnessAppUseCase, | |
getPhoneManufactureData: GetPhoneManufactureDataUseCase | |
) { | |
private val deviceId = getPhoneManufactureData().deviceId | |
suspend operator fun invoke(startDate: Instant): SyncChallengesProgressResult { | |
val now = Clock.System.now() | |
if (startDate.daysUntil(now, TimeZone.currentSystemDefault()) == 0) { | |
return SyncChallengesProgressResult.Success | |
} else { | |
val steps = getStepsFromFitnessApp(startDate, now).getOrElse { | |
return SyncChallengesProgressResult.Failure | |
} | |
val syncResponse = challengesRepository.syncChallengesProgress( | |
SyncChallengesProgressRequest( | |
deviceId = deviceId, | |
steps = ChallengeStepsModelMapper.ChallengeStepsModel(steps) | |
) | |
) | |
return if (syncResponse is ApiResponse.Success && syncResponse.data.success) { | |
SyncChallengesProgressResult.Success | |
} else { | |
SyncChallengesProgressResult.Failure | |
} | |
} | |
} | |
} | |
sealed interface SyncChallengesProgressResult { | |
data object Success : SyncChallengesProgressResult | |
data object Failure : SyncChallengesProgressResult | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment