Integrated the GetUserUseCase use case into the LoginView view for the Login module.

This commit is contained in:
Javier Cicchelli 2022-12-12 23:53:21 +01:00
parent ebee2ddcc0
commit 07ffd2bf80

View File

@ -7,7 +7,9 @@
//
import APIService
import DataModels
import SwiftUI
import UseCases
public struct LoginView: View {
@ -60,13 +62,9 @@ fileprivate extension LoginView {
// MARK: Properties
private let getUser: GetUserUseCase
let authenticated: AuthenticatedClosure
// MARK: Initialisers
init(authenticated: @escaping AuthenticatedClosure) {
self.getUser = .init(authenticated: authenticated)
}
private let getUser: GetUserUseCase = .init()
// MARK: Body
@ -138,9 +136,15 @@ private extension LoginView.LoginContainer {
guard isAuthenticating else { return }
do {
try await getUser(
username: username,
password: password
authenticated(
.init(
username: username,
password: password
),
try await getUser(
username: username,
password: password
)
)
} catch APIClientError.authenticationFailed {
errorMessage = "login.error.authentication_failed.text"
@ -153,6 +157,10 @@ private extension LoginView.LoginContainer {
}
// MARK: - Type aliases
public typealias AuthenticatedClosure = (Account, User) -> Void
// MARK: - Previews
struct LoginView_Previews: PreviewProvider {