Implemented the GetItemsUseCase use case for the Browse module.
This commit is contained in:
parent
d0371c6e48
commit
08edb6b7ec
50
Modules/Sources/Browse/Logic/Use Cases/GetItemsUseCase.swift
Normal file
50
Modules/Sources/Browse/Logic/Use Cases/GetItemsUseCase.swift
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// 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: Dependencies
|
||||
|
||||
@Dependency(\.apiService) private var apiService
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
func callAsFunction(
|
||||
id: String,
|
||||
username: String,
|
||||
password: String
|
||||
) async throws -> [any ModelIdentifiable] {
|
||||
let items = try await apiService.getItems(
|
||||
id: id,
|
||||
credentials: .init(
|
||||
username: username,
|
||||
password: password
|
||||
)
|
||||
)
|
||||
|
||||
return items
|
||||
.compactMap { item -> any ModelIdentifiable in
|
||||
if item.isDirectory {
|
||||
return Folder(
|
||||
id: item.id,
|
||||
name: item.name
|
||||
)
|
||||
} else {
|
||||
return File(
|
||||
id: item.id,
|
||||
name: item.name
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user