Files
vapor-po/Sources/DatabaseClient/Vendors.swift

56 lines
1.3 KiB
Swift

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
}
}
}