main #2

Merged
student-15031 merged 7 commits from student-28725/NTO-2025-Android-TeamTask:main into main 2025-11-29 16:46:27 +00:00
2 changed files with 7 additions and 4 deletions
Showing only changes of commit 67e26d142a - Show all commits

View File

@@ -7,10 +7,9 @@ object AuthRepository {
private var codeCache: String? = null private var codeCache: String? = null
suspend fun checkAndSave(text: String): Result<Boolean> { suspend fun checkAndSave(text: String): Result<Boolean> {
return NetworkDataSource.checkAuth(text).onSuccess { success -> return NetworkDataSource.checkAuth(text).mapCatching { success ->
if (success) { if (success) codeCache = text
codeCache = text success
}
} }
} }
} }

View File

@@ -8,6 +8,10 @@ class CheckAndSaveAuthCodeUseCase(
suspend operator fun invoke( suspend operator fun invoke(
text: String text: String
): Result<Unit> { ): Result<Unit> {
val isValid = text.length == 4 && text.all {it.isLetterOrDigit()}
if (!isValid) return Result.failure(IllegalArgumentException("Неверный формат кода!"))
return repository.checkAndSave(text).mapCatching { success -> return repository.checkAndSave(text).mapCatching { success ->
if (!success) error("Code is incorrect") if (!success) error("Code is incorrect")
} }