64 lines
1.5 KiB
Swift
64 lines
1.5 KiB
Swift
import Dependencies
|
|
import DependenciesMacros
|
|
import SharedModels
|
|
|
|
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 {
|
|
case active
|
|
case all
|
|
case inactive
|
|
}
|
|
}
|
|
}
|
|
|
|
extension DatabaseClient.Employees: TestDependencyKey {
|
|
public static let testValue = Self()
|
|
}
|
|
|
|
public extension Employee {
|
|
struct Create: Codable, Sendable {
|
|
public let firstName: String
|
|
public let lastName: String
|
|
public let active: Bool?
|
|
|
|
public init(
|
|
firstName: String,
|
|
lastName: String,
|
|
active: Bool? = nil
|
|
) {
|
|
self.firstName = firstName
|
|
self.lastName = lastName
|
|
self.active = active
|
|
}
|
|
}
|
|
|
|
struct Update: Codable, Sendable {
|
|
public let firstName: String?
|
|
public let lastName: String?
|
|
public let active: Bool?
|
|
|
|
public init(
|
|
firstName: String? = nil,
|
|
lastName: String? = nil,
|
|
active: Bool? = nil
|
|
) {
|
|
self.firstName = firstName
|
|
self.lastName = lastName
|
|
self.active = active
|
|
}
|
|
}
|
|
}
|