116 lines
2.8 KiB
Swift
116 lines
2.8 KiB
Swift
import CasePathsCore
|
|
import Foundation
|
|
@preconcurrency import URLRouting
|
|
|
|
// TODO: Switch shared to be on API routes not view routes??
|
|
|
|
public enum ApiRoute: Sendable {
|
|
|
|
case employee(EmployeeApiRoute)
|
|
case purchaseOrder(PurchaseOrderApiRoute)
|
|
case user(UserApiRoute)
|
|
case vendor(VendorApiRoute)
|
|
case vendorBranch(VendorBranchApiRoute)
|
|
|
|
static let rootPath = Path { "api"; "v1" }
|
|
|
|
public static let router = OneOf {
|
|
Route(.case(Self.employee)) {
|
|
rootPath
|
|
EmployeeApiRoute.router
|
|
}
|
|
Route(.case(Self.purchaseOrder)) {
|
|
rootPath
|
|
PurchaseOrderApiRoute.router
|
|
}
|
|
Route(.case(Self.user)) {
|
|
rootPath
|
|
UserApiRoute.router
|
|
}
|
|
Route(.case(Self.vendor)) {
|
|
rootPath
|
|
VendorApiRoute.router
|
|
}
|
|
Route(.case(Self.vendorBranch)) {
|
|
rootPath
|
|
VendorBranchApiRoute.router
|
|
}
|
|
}
|
|
|
|
public enum EmployeeApiRoute: Sendable {
|
|
case shared(SharedEmployeeRoute)
|
|
|
|
public static let router = Route(.case(Self.shared)) {
|
|
SharedEmployeeRoute.router
|
|
}
|
|
}
|
|
|
|
public enum PurchaseOrderApiRoute: Sendable {
|
|
case shared(SharedPurchaseOrderRoute)
|
|
|
|
public static let router = Route(.case(Self.shared)) {
|
|
SharedPurchaseOrderRoute.router
|
|
}
|
|
}
|
|
|
|
// TODO: Add logout.
|
|
public enum UserApiRoute: Sendable {
|
|
case shared(SharedUserRoute)
|
|
|
|
public static let router = Route(.case(Self.shared)) {
|
|
SharedUserRoute.router
|
|
}
|
|
}
|
|
|
|
public enum VendorApiRoute: Sendable {
|
|
case index(withBranches: Bool?)
|
|
case shared(SharedVendorRoute)
|
|
|
|
static let rootPath = "vendors"
|
|
|
|
public static let router = OneOf {
|
|
Route(.case(Self.index(withBranches:))) {
|
|
Path { rootPath }
|
|
Method.get
|
|
Query {
|
|
Field("branches", default: nil) {
|
|
Optionally { Bool.parser() }
|
|
}
|
|
}
|
|
}
|
|
Route(.case(Self.shared)) {
|
|
SharedVendorRoute.router
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum VendorBranchApiRoute: Sendable {
|
|
case get(id: VendorBranch.ID)
|
|
case index(for: Vendor.ID? = nil)
|
|
case shared(SharedVendorBranchRoute)
|
|
case update(id: VendorBranch.ID, updates: VendorBranch.Update)
|
|
|
|
public static let router = OneOf {
|
|
Route(.case(Self.get(id:))) {
|
|
Path { "vendors"; "branches"; VendorBranch.ID.parser() }
|
|
Method.get
|
|
}
|
|
Route(.case(Self.index(for:))) {
|
|
Path { "vendors"; "branches" }
|
|
Method.get
|
|
Query {
|
|
Field("vendorID", default: nil) { Optionally { VendorBranch.ID.parser() } }
|
|
}
|
|
}
|
|
Route(.case(Self.shared)) {
|
|
SharedVendorBranchRoute.router
|
|
}
|
|
Route(.case(Self.update(id:updates:))) {
|
|
Path { "vendors"; "branches"; VendorBranch.ID.parser() }
|
|
Method.put
|
|
Body(.json(VendorBranch.Update.self))
|
|
}
|
|
}
|
|
}
|
|
}
|