forked from student-15031/NTO-2025-Android-TeamTask
merge upstream
This commit is contained in:
@@ -7,10 +7,9 @@ object AuthRepository {
|
||||
private var codeCache: String? = null
|
||||
|
||||
suspend fun checkAndSave(text: String): Result<Boolean> {
|
||||
return NetworkDataSource.checkAuth(text).onSuccess { success ->
|
||||
if (success) {
|
||||
codeCache = text
|
||||
}
|
||||
return NetworkDataSource.checkAuth(text).mapCatching { success ->
|
||||
if (success) codeCache = text
|
||||
success
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,10 @@ class CheckAndSaveAuthCodeUseCase(
|
||||
suspend operator fun invoke(
|
||||
text: String
|
||||
): Result<Unit> {
|
||||
|
||||
val isValid = text.length == 4 && text.all {it.isLetterOrDigit()}
|
||||
if (!isValid) return Result.failure(IllegalArgumentException("Неверный формат кода!"))
|
||||
|
||||
return repository.checkAndSave(text).mapCatching { success ->
|
||||
if (!success) error("Code is incorrect")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user