Fixed the initialisation of the keychain storage in the GetUserUseCase use case

This commit is contained in:
Javier Cicchelli 2022-12-20 03:34:24 +01:00
parent e9a7e8b33b
commit 3ecf5c7468
2 changed files with 9 additions and 15 deletions

View File

@ -95,7 +95,7 @@ private extension ContentView {
do { do {
user = try await getUser() user = try await getUser()
} catch { } catch {
// TODO: Handle this error appropriately. showSheet = .login
} }
} }
} }

View File

@ -14,26 +14,24 @@ import KeychainStorage
public actor GetUserUseCase { public actor GetUserUseCase {
// MARK: Storages
@KeychainStorage(key: .KeychainStorage.account) var account: Account?
// MARK: Properties // MARK: Properties
private let apiService: APIService private let apiService: APIService
private var account: Account?
// MARK: Initialisers // MARK: Initialisers
public init( public init(apiService: APIService) {
apiService: APIService,
account: Account?
) {
self.apiService = apiService self.apiService = apiService
self.account = account
} }
// MARK: Functions // MARK: Functions
public func callAsFunction() async throws -> User { public func callAsFunction() async throws -> User {
guard let account else { throw GetUserError .accountNotFound } guard let account else { throw GetUserError.accountNotFound }
return try await getUser( return try await getUser(
username: account.username, username: account.username,
@ -65,12 +63,8 @@ public actor GetUserUseCase {
public extension GetUserUseCase { public extension GetUserUseCase {
init() { init() {
@Dependency(\.apiService) var apiService @Dependency(\.apiService) var apiService
@KeychainStorage(key: .KeychainStorage.account) var account: Account?
self.init(apiService: apiService)
self.init(
apiService: apiService,
account: account
)
} }
} }