49 lines
1.3 KiB
Swift
49 lines
1.3 KiB
Swift
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
|
|
}
|
|
}
|
|
}
|