feat: Begins breaking database out into it's own module, using dependencies
This commit is contained in:
55
Sources/DatabaseClient/Vendors.swift
Normal file
55
Sources/DatabaseClient/Vendors.swift
Normal file
@@ -0,0 +1,55 @@
|
||||
import Dependencies
|
||||
import DependenciesMacros
|
||||
import SharedModels
|
||||
|
||||
public extension DatabaseClient {
|
||||
@DependencyClient
|
||||
struct Vendors: Sendable {
|
||||
public var create: @Sendable (Vendor.Create) async throws -> Vendor
|
||||
public var delete: @Sendable (Vendor.ID) async throws -> Void
|
||||
public var fetchAll: @Sendable (FetchRequest) async throws -> [Vendor]
|
||||
public var get: @Sendable (Vendor.ID, GetRequest) async throws -> Vendor?
|
||||
public var update: @Sendable (Vendor.ID, Vendor.Update) async throws -> Vendor
|
||||
|
||||
public enum FetchRequest {
|
||||
case all
|
||||
case withBranches
|
||||
}
|
||||
|
||||
public enum GetRequest {
|
||||
case all
|
||||
case withBranches
|
||||
}
|
||||
|
||||
public func fetchAll() async throws -> [Vendor] {
|
||||
try await fetchAll(.all)
|
||||
}
|
||||
|
||||
public func get(_ id: Vendor.ID) async throws -> Vendor? {
|
||||
try await get(id, .all)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseClient.Vendors: TestDependencyKey {
|
||||
public static let testValue: DatabaseClient.Vendors = Self()
|
||||
}
|
||||
|
||||
public extension Vendor {
|
||||
|
||||
struct Create: Codable, Sendable {
|
||||
public let name: String
|
||||
|
||||
public init(name: String) {
|
||||
self.name = name
|
||||
}
|
||||
}
|
||||
|
||||
struct Update: Codable, Sendable {
|
||||
public let name: String?
|
||||
|
||||
public init(name: String?) {
|
||||
self.name = name
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user