2022-12-12 00:53:53 +01:00
|
|
|
//
|
|
|
|
// GetUserUseCase.swift
|
|
|
|
// Login
|
|
|
|
//
|
|
|
|
// Created by Javier Cicchelli on 12/12/2022.
|
|
|
|
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import APIService
|
2022-12-12 23:06:56 +01:00
|
|
|
import DataModels
|
2022-12-12 00:53:53 +01:00
|
|
|
import DependencyInjection
|
|
|
|
import Dependencies
|
|
|
|
|
2022-12-12 23:06:56 +01:00
|
|
|
public struct GetUserUseCase {
|
2022-12-12 00:53:53 +01:00
|
|
|
|
|
|
|
// MARK: Dependencies
|
|
|
|
|
|
|
|
@Dependency(\.apiService) private var apiService
|
|
|
|
|
2022-12-12 23:06:56 +01:00
|
|
|
// MARK: Initialisers
|
2022-12-12 00:53:53 +01:00
|
|
|
|
2022-12-12 23:06:56 +01:00
|
|
|
public init() {}
|
2022-12-12 00:53:53 +01:00
|
|
|
|
|
|
|
// MARK: Functions
|
|
|
|
|
2022-12-12 23:06:56 +01:00
|
|
|
public func callAsFunction(
|
2022-12-12 00:53:53 +01:00
|
|
|
username: String,
|
|
|
|
password: String
|
2022-12-12 23:06:56 +01:00
|
|
|
) async throws -> User {
|
2022-12-12 00:53:53 +01:00
|
|
|
let me = try await apiService.getUser(
|
|
|
|
credentials: .init(
|
|
|
|
username: username,
|
|
|
|
password: password
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2022-12-12 23:06:56 +01:00
|
|
|
return .init(
|
|
|
|
profile: .init(
|
|
|
|
firstName: me.firstName,
|
|
|
|
lastName: me.lastName
|
2022-12-12 00:53:53 +01:00
|
|
|
),
|
2022-12-12 23:06:56 +01:00
|
|
|
rootFolder: .init(
|
|
|
|
id: me.rootItem.id,
|
|
|
|
name: me.rootItem.name,
|
|
|
|
lastModifiedAt: me.rootItem.lastModifiedAt
|
2022-12-12 00:53:53 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|