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