35 lines
960 B
Swift
35 lines
960 B
Swift
import Dependencies
|
|
import DependenciesMacros
|
|
import SharedModels
|
|
import Vapor
|
|
|
|
public extension DatabaseClient {
|
|
|
|
@DependencyClient
|
|
struct Employees: Sendable {
|
|
public var create: @Sendable (Employee.Create) async throws -> Employee
|
|
public var delete: @Sendable (Employee.ID) async throws -> Void
|
|
public var fetchAll: @Sendable (FetchRequest) async throws -> [Employee]
|
|
public var get: @Sendable (Employee.ID) async throws -> Employee?
|
|
public var update: @Sendable (Employee.ID, Employee.Update) async throws -> Employee
|
|
|
|
public func fetchAll() async throws -> [Employee] {
|
|
try await fetchAll(.all)
|
|
}
|
|
|
|
public enum FetchRequest: String, Content {
|
|
case active
|
|
case all
|
|
case inactive
|
|
}
|
|
}
|
|
}
|
|
|
|
extension Employee: Content {}
|
|
extension Employee.Create: Content {}
|
|
extension Employee.Update: Content {}
|
|
|
|
extension DatabaseClient.Employees: TestDependencyKey {
|
|
public static let testValue = Self()
|
|
}
|