// // GetItemsUseCase.swift // Browse // // Created by Javier Cicchelli on 13/12/2022. // Copyright © 2022 Röck+Cöde. All rights reserved. // import APIService import DependencyInjection import Dependencies struct GetItemsUseCase { // MARK: Properties let apiService: APIService // MARK: Functions func callAsFunction( id: String, username: String, password: String ) async throws -> [any FileSystemItem] { let items = try await apiService.getItems( id: id, credentials: .init( username: username, password: password ) ) return items .compactMap { item -> any FileSystemItem in if item.isDirectory { return Folder( id: item.id, name: item.name ) } else { return Document( id: item.id, name: item.name, contentType: item.contentType ?? "-", size: item.size ?? 0, lastModifiedAt: item.lastModifiedAt ) } } } } // MARK: - Initialisers extension GetItemsUseCase { init() { @Dependency(\.apiService) var apiService self.init(apiService: apiService) } }