Created
April 29, 2023 18:10
-
-
Save o-nnerb/487d460d34b77dc87480cf37b74fe1f3 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
import Injection | |
import Domain | |
protocol LoginInteractorInput { | |
func validate(email: String) | |
func validate(password: String) | |
func login(_ email: String, _ password: String) | |
} | |
protocol LoginInteractorOutput: AnyObject { | |
func email(isValid: Bool) | |
func password(isValid: Bool) | |
func login(_ result: Result<Void, Error>) | |
} | |
class LoginInteractor { | |
// MARK: - Use Cases | |
@Injected var loginUseCase: LoginUseCaseProtocol | |
// MARK: - Properties | |
private(set) weak var presenter: LoginInteractorOutput! | |
init(presenter: LoginInteractorOutput) { | |
self.presenter = presenter | |
} | |
} | |
extension LoginInteractor: LoginInteractorInput { | |
func validate(email: String) { | |
presenter?.email(isValid: !email.isEmpty) | |
} | |
func validate(password: String) { | |
presenter?.password(isValid: !password.isEmpty) | |
} | |
func login(_ email: String, _ password: String) { | |
Task { | |
do { | |
try await loginUseCase(email, password) | |
presenter?.login(.success(())) | |
} catch { | |
presenter?.login(.failure(error)) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment