feat: Begins breaking database out into it's own module, using dependencies
This commit is contained in:
63
Sources/DatabaseClient/Employees.swift
Normal file
63
Sources/DatabaseClient/Employees.swift
Normal file
@@ -0,0 +1,63 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user