2022-12-13 02:03:38 +01:00
|
|
|
//
|
|
|
|
// 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 {
|
|
|
|
|
2022-12-16 16:37:49 +01:00
|
|
|
// MARK: Properties
|
2022-12-13 02:03:38 +01:00
|
|
|
|
2022-12-16 16:37:49 +01:00
|
|
|
let apiService: APIService
|
2022-12-13 02:03:38 +01:00
|
|
|
|
|
|
|
// MARK: Functions
|
|
|
|
|
|
|
|
func callAsFunction(
|
|
|
|
id: String,
|
|
|
|
username: String,
|
|
|
|
password: String
|
2022-12-16 17:20:19 +01:00
|
|
|
) async throws -> [any FileSystemItem] {
|
2022-12-13 02:03:38 +01:00
|
|
|
let items = try await apiService.getItems(
|
|
|
|
id: id,
|
|
|
|
credentials: .init(
|
|
|
|
username: username,
|
|
|
|
password: password
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
return items
|
2022-12-16 17:20:19 +01:00
|
|
|
.compactMap { item -> any FileSystemItem in
|
2022-12-13 02:03:38 +01:00
|
|
|
if item.isDirectory {
|
|
|
|
return Folder(
|
|
|
|
id: item.id,
|
|
|
|
name: item.name
|
|
|
|
)
|
|
|
|
} else {
|
2022-12-14 01:12:27 +01:00
|
|
|
return Document(
|
2022-12-13 02:03:38 +01:00
|
|
|
id: item.id,
|
2022-12-14 01:12:27 +01:00
|
|
|
name: item.name,
|
|
|
|
contentType: item.contentType ?? "-",
|
|
|
|
size: item.size ?? 0,
|
|
|
|
lastModifiedAt: item.lastModifiedAt
|
2022-12-13 02:03:38 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-12-16 16:37:49 +01:00
|
|
|
|
|
|
|
// MARK: - Initialisers
|
|
|
|
|
|
|
|
extension GetItemsUseCase {
|
|
|
|
init() {
|
|
|
|
@Dependency(\.apiService) var apiService
|
|
|
|
|
|
|
|
self.init(apiService: apiService)
|
|
|
|
}
|
|
|
|
}
|