Implemented the GetUserUseCase use case for the Login module.
This commit is contained in:
parent
e7ed33549c
commit
27d2848a45
@ -6,7 +6,7 @@
|
||||
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
||||
//
|
||||
|
||||
public struct Account: Codable {
|
||||
public struct Account: Codable, Equatable {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
|
11
Modules/Sources/Login/Logic/Defines/Typealiases.swift
Normal file
11
Modules/Sources/Login/Logic/Defines/Typealiases.swift
Normal file
@ -0,0 +1,11 @@
|
||||
//
|
||||
// Typealiases.swift
|
||||
// Login
|
||||
//
|
||||
// Created by Javier Cicchelli on 12/12/2022.
|
||||
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
||||
//
|
||||
|
||||
import DataModels
|
||||
|
||||
public typealias LoginSuccessClosure = (Account, User) -> Void
|
55
Modules/Sources/Login/Logic/Use Cases/GetUserUseCase.swift
Normal file
55
Modules/Sources/Login/Logic/Use Cases/GetUserUseCase.swift
Normal file
@ -0,0 +1,55 @@
|
||||
//
|
||||
// GetUserUseCase.swift
|
||||
// Login
|
||||
//
|
||||
// Created by Javier Cicchelli on 12/12/2022.
|
||||
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
||||
//
|
||||
|
||||
import APIService
|
||||
import DependencyInjection
|
||||
import Dependencies
|
||||
|
||||
struct GetUserUseCase {
|
||||
|
||||
// MARK: Dependencies
|
||||
|
||||
@Dependency(\.apiService) private var apiService
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
let success: LoginSuccessClosure
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
func callAsFunction(
|
||||
username: String,
|
||||
password: String
|
||||
) async throws {
|
||||
let me = try await apiService.getUser(
|
||||
credentials: .init(
|
||||
username: username,
|
||||
password: password
|
||||
)
|
||||
)
|
||||
|
||||
success(
|
||||
.init(
|
||||
username: username,
|
||||
password: password
|
||||
),
|
||||
.init(
|
||||
profile: .init(
|
||||
firstName: me.firstName,
|
||||
lastName: me.lastName
|
||||
),
|
||||
rootFolder: .init(
|
||||
id: me.rootItem.id,
|
||||
name: me.rootItem.name,
|
||||
lastModifiedAt: me.rootItem.lastModifiedAt
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user