feat: Refactoring route declarations.
This commit is contained in:
115
Sources/SharedModels/Routes/ApiRoute.swift
Normal file
115
Sources/SharedModels/Routes/ApiRoute.swift
Normal file
@@ -0,0 +1,115 @@
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
165
Sources/SharedModels/Routes/SharedRoutes.swift
Normal file
165
Sources/SharedModels/Routes/SharedRoutes.swift
Normal file
@@ -0,0 +1,165 @@
|
||||
import CasePathsCore
|
||||
import Foundation
|
||||
@preconcurrency import URLRouting
|
||||
|
||||
public enum SharedEmployeeRoute: Sendable {
|
||||
case create(Employee.Create)
|
||||
case delete(id: Employee.ID)
|
||||
case get(id: Employee.ID)
|
||||
case index
|
||||
case update(id: Employee.ID, updates: Employee.Update)
|
||||
|
||||
static let rootPath = "employees"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.create)) {
|
||||
Path { rootPath }
|
||||
Method.post
|
||||
Body(.json(Employee.Create.self))
|
||||
}
|
||||
Route(.case(Self.index)) {
|
||||
Path { rootPath }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.delete(id:))) {
|
||||
Path { rootPath; UUID.parser() }
|
||||
Method.delete
|
||||
}
|
||||
Route(.case(Self.get(id:))) {
|
||||
Path { rootPath; UUID.parser() }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.update(id:updates:))) {
|
||||
Path { rootPath; UUID.parser() }
|
||||
Method.put
|
||||
Body(.json(Employee.Update.self))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum SharedPurchaseOrderRoute: Sendable {
|
||||
case create(PurchaseOrder.Create)
|
||||
case delete(id: PurchaseOrder.ID)
|
||||
case get(id: PurchaseOrder.ID)
|
||||
case index
|
||||
case page(page: Int, limit: Int)
|
||||
|
||||
static let rootPath = "purchase-orders"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.create)) {
|
||||
Path { rootPath }
|
||||
Method.post
|
||||
Body(.json(PurchaseOrder.Create.self))
|
||||
}
|
||||
Route(.case(Self.delete(id:))) {
|
||||
Path { rootPath; Digits() }
|
||||
Method.delete
|
||||
}
|
||||
Route(.case(Self.get(id:))) {
|
||||
Path { rootPath; Digits() }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.index)) {
|
||||
Path { rootPath }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.page(page:limit:))) {
|
||||
Path { rootPath; "next" }
|
||||
Method.get
|
||||
Query {
|
||||
Field("page", default: 1) { Digits() }
|
||||
Field("limit", default: 25) { Digits() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum SharedUserRoute: Sendable {
|
||||
case create(User.Create)
|
||||
case delete(id: User.ID)
|
||||
case get(id: User.ID)
|
||||
case index
|
||||
case login(User.Login)
|
||||
case update(id: User.ID, updates: User.Update)
|
||||
|
||||
static let rootPath = "users"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.create)) {
|
||||
Path { rootPath }
|
||||
Method.post
|
||||
Body(.json(User.Create.self))
|
||||
}
|
||||
Route(.case(Self.delete(id:))) {
|
||||
Path { rootPath; User.ID.parser() }
|
||||
Method.delete
|
||||
}
|
||||
Route(.case(Self.get(id:))) {
|
||||
Path { rootPath; User.ID.parser() }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.index)) {
|
||||
Path { rootPath }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.login)) {
|
||||
Path { rootPath }
|
||||
Method.post
|
||||
Body(.json(User.Login.self))
|
||||
}
|
||||
Route(.case(Self.update(id:updates:))) {
|
||||
Path { rootPath; User.ID.parser() }
|
||||
// TODO: Use put or patch.
|
||||
Method.post
|
||||
Body(.json(User.Update.self))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum SharedVendorRoute: Sendable {
|
||||
case create(Vendor.Create)
|
||||
case delete(id: Vendor.ID)
|
||||
case get(id: Vendor.ID)
|
||||
case update(id: Vendor.ID, updates: Vendor.Update)
|
||||
|
||||
static let rootPath = "vendors"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.create)) {
|
||||
Path { rootPath }
|
||||
Method.post
|
||||
Body(.json(Vendor.Create.self))
|
||||
}
|
||||
Route(.case(Self.delete(id:))) {
|
||||
Path { rootPath; Vendor.ID.parser() }
|
||||
Method.delete
|
||||
}
|
||||
Route(.case(Self.get(id:))) {
|
||||
Path { rootPath; Vendor.ID.parser() }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.update(id:updates:))) {
|
||||
Path { rootPath; Vendor.ID.parser() }
|
||||
Method.put
|
||||
Body(.json(Vendor.Update.self))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum SharedVendorBranchRoute: Sendable {
|
||||
case create(VendorBranch.Create)
|
||||
case delete(id: VendorBranch.ID)
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.create)) {
|
||||
Path { "vendors"; "branches" }
|
||||
Method.post
|
||||
Body(.json(VendorBranch.Create.self))
|
||||
}
|
||||
Route(.case(Self.delete(id:))) {
|
||||
Path { "vendors"; "branches"; VendorBranch.ID.parser() }
|
||||
Method.delete
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Sources/SharedModels/Routes/SiteRoute.swift
Normal file
18
Sources/SharedModels/Routes/SiteRoute.swift
Normal file
@@ -0,0 +1,18 @@
|
||||
import CasePathsCore
|
||||
import Foundation
|
||||
@preconcurrency import URLRouting
|
||||
|
||||
public enum SiteRoute: Sendable {
|
||||
case api(ApiRoute)
|
||||
case health
|
||||
case view(ViewRoute)
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.view)) { ViewRoute.router }
|
||||
Route(.case(Self.health)) {
|
||||
Path { "health" }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.api)) { ApiRoute.router }
|
||||
}
|
||||
}
|
||||
218
Sources/SharedModels/Routes/ViewRoute.swift
Normal file
218
Sources/SharedModels/Routes/ViewRoute.swift
Normal file
@@ -0,0 +1,218 @@
|
||||
import CasePathsCore
|
||||
import Foundation
|
||||
@preconcurrency import URLRouting
|
||||
|
||||
public enum ViewRoute: Sendable {
|
||||
|
||||
case employee(EmployeeRoute)
|
||||
case login
|
||||
case purchaseOrder(PurchaseOrderRoute)
|
||||
case select(SelectRoute)
|
||||
case user(UserRoute)
|
||||
case vendor(VendorRoute)
|
||||
case vendorBranch(VendorBranchRoute)
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.employee)) { EmployeeRoute.router }
|
||||
Route(.case(Self.login)) {
|
||||
Path { "login" }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.purchaseOrder)) { PurchaseOrderRoute.router }
|
||||
Route(.case(Self.select)) { SelectRoute.router }
|
||||
Route(.case(Self.user)) { UserRoute.router }
|
||||
Route(.case(Self.vendor)) { VendorRoute.router }
|
||||
Route(.case(Self.vendorBranch)) { VendorBranchRoute.router }
|
||||
}
|
||||
|
||||
public enum EmployeeRoute: Sendable {
|
||||
case form
|
||||
case shared(SharedEmployeeRoute)
|
||||
|
||||
public static func delete(id: Employee.ID) -> Self {
|
||||
.shared(.delete(id: id))
|
||||
}
|
||||
|
||||
public static func get(id: Employee.ID) -> Self {
|
||||
.shared(.get(id: id))
|
||||
}
|
||||
|
||||
public static var index: Self { .shared(.index) }
|
||||
|
||||
static let rootPath = "employees"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.form)) {
|
||||
Path { rootPath; "create" }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.shared)) {
|
||||
SharedEmployeeRoute.router
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum PurchaseOrderRoute: Sendable {
|
||||
case form
|
||||
case search(Search)
|
||||
case shared(SharedPurchaseOrderRoute)
|
||||
|
||||
static let rootPath = "purchase-orders"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.form)) {
|
||||
Path { rootPath; "create" }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.search)) {
|
||||
Search.router
|
||||
}
|
||||
Route(.case(Self.shared)) {
|
||||
SharedPurchaseOrderRoute.router
|
||||
}
|
||||
}
|
||||
|
||||
public enum Search: Sendable {
|
||||
case index(context: Context? = nil, table: Bool? = nil)
|
||||
case search(Request)
|
||||
|
||||
static let rootPath = Path { "purchase-orders"; "search" }
|
||||
|
||||
static let router = OneOf {
|
||||
Route(.case(Search.index(context:table:))) {
|
||||
rootPath
|
||||
Method.get
|
||||
Query {
|
||||
Field("context", default: .employee) { Optionally { Search.Context.parser() } }
|
||||
Field("table", default: nil) { Optionally { Bool.parser() } }
|
||||
}
|
||||
}
|
||||
Route(.case(Search.search)) {
|
||||
rootPath
|
||||
Method.post
|
||||
Body(.json(Search.Request.self))
|
||||
}
|
||||
}
|
||||
|
||||
public enum Context: String, Codable, CaseIterable, Sendable {
|
||||
case employee
|
||||
case customer
|
||||
case vendor
|
||||
}
|
||||
|
||||
public struct Request: Codable, Sendable {
|
||||
public let context: Context
|
||||
public let createdForID: Employee.ID?
|
||||
public let customerSearch: String?
|
||||
public let vendorBranchID: VendorBranch.ID?
|
||||
|
||||
public init(
|
||||
context: Context,
|
||||
createdForID: Employee.ID? = nil,
|
||||
customerSearch: String? = nil,
|
||||
vendorBranchID: VendorBranch.ID? = nil
|
||||
) {
|
||||
self.context = context
|
||||
self.createdForID = createdForID
|
||||
self.customerSearch = customerSearch
|
||||
self.vendorBranchID = vendorBranchID
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Move into respective view routes.
|
||||
public enum SelectRoute: Sendable {
|
||||
case employee(context: Context)
|
||||
case vendorBranches(context: Context)
|
||||
|
||||
public enum Context: String, Codable, Sendable, CaseIterable {
|
||||
case purchaseOrderForm
|
||||
case purchaseOrderSearch
|
||||
}
|
||||
|
||||
static let rootPath = "select"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.employee(context:))) {
|
||||
Path { rootPath; "employee" }
|
||||
Method.get
|
||||
Query {
|
||||
Field("context") { Context.parser() }
|
||||
}
|
||||
}
|
||||
Route(.case(Self.vendorBranches(context:))) {
|
||||
Path { rootPath; "vendor-branches" }
|
||||
Method.get
|
||||
Query {
|
||||
Field("context") { Context.parser() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum UserRoute: Sendable {
|
||||
case form
|
||||
case shared(SharedUserRoute)
|
||||
|
||||
static let rootPath = "users"
|
||||
|
||||
public static func delete(id: User.ID) -> Self {
|
||||
.shared(.delete(id: id))
|
||||
}
|
||||
|
||||
public static var index: Self { .shared(.index) }
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.form)) {
|
||||
Path { rootPath; "create" }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.shared)) {
|
||||
SharedUserRoute.router
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum VendorRoute: Sendable {
|
||||
case form
|
||||
case shared(SharedVendorRoute)
|
||||
|
||||
static let rootPath = "vendors"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.form)) {
|
||||
Path { rootPath; "create" }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.shared)) {
|
||||
SharedVendorRoute.router
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add Select
|
||||
public enum VendorBranchRoute: Sendable {
|
||||
|
||||
case index(vendorID: Vendor.ID)
|
||||
case shared(SharedVendorBranchRoute)
|
||||
|
||||
public static func delete(id: VendorBranch.ID) -> Self {
|
||||
.shared(.delete(id: id))
|
||||
}
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.index(vendorID:))) {
|
||||
Path { "vendors"; "branches" }
|
||||
Method.get
|
||||
Query {
|
||||
Field("vendorID") { Vendor.ID.parser() }
|
||||
}
|
||||
}
|
||||
Route(.case(Self.shared)) {
|
||||
SharedVendorBranchRoute.router
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,422 +0,0 @@
|
||||
import CasePathsCore
|
||||
import Foundation
|
||||
@preconcurrency import URLRouting
|
||||
|
||||
public enum SiteRoute: Sendable {
|
||||
case api(ApiRoute)
|
||||
case health
|
||||
case view(ViewRoute)
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.view)) { ViewRoute.router }
|
||||
Route(.case(Self.health)) {
|
||||
Path { "health" }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.api)) { ApiRoute.router }
|
||||
}
|
||||
}
|
||||
|
||||
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 create(Employee.Create)
|
||||
case delete(id: Employee.ID)
|
||||
case get(id: Employee.ID)
|
||||
case index
|
||||
case update(id: Employee.ID, updates: Employee.Update)
|
||||
|
||||
static let rootPath = "employees"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.create)) {
|
||||
Path { rootPath }
|
||||
Method.post
|
||||
Body(.json(Employee.Create.self))
|
||||
}
|
||||
Route(.case(Self.index)) {
|
||||
Path { rootPath }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.delete(id:))) {
|
||||
Path { rootPath; UUID.parser() }
|
||||
Method.delete
|
||||
}
|
||||
Route(.case(Self.get(id:))) {
|
||||
Path { rootPath; UUID.parser() }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.update(id:updates:))) {
|
||||
Path { rootPath; UUID.parser() }
|
||||
Method.put
|
||||
Body(.json(Employee.Update.self))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum PurchaseOrderApiRoute: Sendable {
|
||||
case create(PurchaseOrder.Create)
|
||||
case delete(id: PurchaseOrder.ID)
|
||||
case get(id: PurchaseOrder.ID)
|
||||
case index
|
||||
case page(page: Int, limit: Int)
|
||||
|
||||
static let rootPath = "purchase-orders"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.create)) {
|
||||
Path { rootPath }
|
||||
Method.post
|
||||
Body(.json(PurchaseOrder.Create.self))
|
||||
}
|
||||
Route(.case(Self.delete(id:))) {
|
||||
Path { rootPath; Digits() }
|
||||
Method.delete
|
||||
}
|
||||
Route(.case(Self.get(id:))) {
|
||||
Path { rootPath; Digits() }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.index)) {
|
||||
Path { rootPath }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.page(page:limit:))) {
|
||||
Path { rootPath; "next" }
|
||||
Method.get
|
||||
Query {
|
||||
Field("page", default: 1) { Digits() }
|
||||
Field("limit", default: 25) { Digits() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add logout.
|
||||
public enum UserApiRoute: Sendable {
|
||||
case create(User.Create)
|
||||
case delete(id: User.ID)
|
||||
case get(id: User.ID)
|
||||
case index
|
||||
case login(User.Login)
|
||||
case update(id: User.ID, updates: User.Update)
|
||||
|
||||
static let rootPath = "users"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.create)) {
|
||||
Path { rootPath }
|
||||
Method.post
|
||||
Body(.json(User.Create.self))
|
||||
}
|
||||
Route(.case(Self.delete(id:))) {
|
||||
Path { rootPath; User.ID.parser() }
|
||||
Method.delete
|
||||
}
|
||||
Route(.case(Self.get(id:))) {
|
||||
Path { rootPath; User.ID.parser() }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.index)) {
|
||||
Path { rootPath }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.login)) {
|
||||
Path { rootPath }
|
||||
Method.post
|
||||
Body(.json(User.Login.self))
|
||||
}
|
||||
Route(.case(Self.update(id:updates:))) {
|
||||
Path { rootPath; User.ID.parser() }
|
||||
// TODO: Use put or patch.
|
||||
Method.post
|
||||
Body(.json(User.Update.self))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum VendorApiRoute: Sendable {
|
||||
case create(Vendor.Create)
|
||||
case delete(id: Vendor.ID)
|
||||
case get(id: Vendor.ID)
|
||||
case index(withBranches: Bool?)
|
||||
case update(id: Vendor.ID, updates: Vendor.Update)
|
||||
|
||||
static let rootPath = "vendors"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.create)) {
|
||||
Path { rootPath }
|
||||
Method.post
|
||||
Body(.json(Vendor.Create.self))
|
||||
}
|
||||
Route(.case(Self.delete(id:))) {
|
||||
Path { rootPath; Vendor.ID.parser() }
|
||||
Method.delete
|
||||
}
|
||||
Route(.case(Self.get(id:))) {
|
||||
Path { rootPath; Vendor.ID.parser() }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.index(withBranches:))) {
|
||||
Path { rootPath }
|
||||
Method.get
|
||||
Query {
|
||||
Field("branches", default: nil) {
|
||||
Optionally { Bool.parser() }
|
||||
}
|
||||
}
|
||||
}
|
||||
Route(.case(Self.update(id:updates:))) {
|
||||
Path { rootPath; Vendor.ID.parser() }
|
||||
Method.put
|
||||
Body(.json(Vendor.Update.self))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum VendorBranchApiRoute: Sendable {
|
||||
case create(VendorBranch.Create)
|
||||
case delete(id: VendorBranch.ID)
|
||||
case get(id: VendorBranch.ID)
|
||||
case index(for: Vendor.ID? = nil)
|
||||
case update(id: VendorBranch.ID, updates: VendorBranch.Update)
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.create)) {
|
||||
Path { "vendors"; "branches" }
|
||||
Method.post
|
||||
Body(.json(VendorBranch.Create.self))
|
||||
}
|
||||
Route(.case(Self.delete(id:))) {
|
||||
Path { "vendors"; "branches"; VendorBranch.ID.parser() }
|
||||
Method.delete
|
||||
}
|
||||
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.update(id:updates:))) {
|
||||
Path { "vendors"; "branches"; VendorBranch.ID.parser() }
|
||||
Method.put
|
||||
Body(.json(VendorBranch.Update.self))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum ViewRoute: Sendable {
|
||||
|
||||
case employee(EmployeeRoute)
|
||||
case login
|
||||
case purchaseOrder(PurchaseOrderRoute)
|
||||
case select(SelectRoute)
|
||||
case user(UserRoute)
|
||||
case vendor(VendorRoute)
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.employee)) { EmployeeRoute.router }
|
||||
Route(.case(Self.login)) {
|
||||
Path { "login" }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.purchaseOrder)) { PurchaseOrderRoute.router }
|
||||
Route(.case(Self.select)) { SelectRoute.router }
|
||||
Route(.case(Self.user)) { UserRoute.router }
|
||||
Route(.case(Self.vendor)) { VendorRoute.router }
|
||||
}
|
||||
|
||||
public enum EmployeeRoute: Sendable {
|
||||
case form
|
||||
case shared(ApiRoute.EmployeeApiRoute)
|
||||
|
||||
static let rootPath = "employees"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.form)) {
|
||||
Path { rootPath; "create" }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.shared)) {
|
||||
ApiRoute.EmployeeApiRoute.router
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum PurchaseOrderRoute: Sendable {
|
||||
case form
|
||||
case search(Search)
|
||||
case shared(ApiRoute.PurchaseOrderApiRoute)
|
||||
|
||||
static let rootPath = "purchase-orders"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.form)) {
|
||||
Path { rootPath; "create" }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.search)) {
|
||||
Search.router
|
||||
}
|
||||
Route(.case(Self.shared)) {
|
||||
ApiRoute.PurchaseOrderApiRoute.router
|
||||
}
|
||||
}
|
||||
|
||||
public enum Search: Sendable {
|
||||
case index(context: Context, table: Bool?)
|
||||
case search(Request)
|
||||
|
||||
static let rootPath = Path { "purchase-orders"; "search" }
|
||||
|
||||
static let router = OneOf {
|
||||
Route(.case(Search.index(context:table:))) {
|
||||
rootPath
|
||||
Method.get
|
||||
Query {
|
||||
Field("context", default: .employee) { Search.Context.parser() }
|
||||
Field("table", default: nil) { Optionally { Bool.parser() } }
|
||||
}
|
||||
}
|
||||
Route(.case(Search.search)) {
|
||||
rootPath
|
||||
Method.post
|
||||
Body(.json(Search.Request.self))
|
||||
}
|
||||
}
|
||||
|
||||
public enum Context: String, Codable, CaseIterable, Sendable {
|
||||
case employee
|
||||
case customer
|
||||
case vendor
|
||||
}
|
||||
|
||||
public struct Request: Codable, Sendable {
|
||||
public let context: Context
|
||||
public let createdForID: Employee.ID?
|
||||
public let customerSearch: String?
|
||||
public let vendorBranchID: VendorBranch.ID?
|
||||
|
||||
public init(
|
||||
context: Context,
|
||||
createdForID: Employee.ID? = nil,
|
||||
customerSearch: String? = nil,
|
||||
vendorBranchID: VendorBranch.ID? = nil
|
||||
) {
|
||||
self.context = context
|
||||
self.createdForID = createdForID
|
||||
self.customerSearch = customerSearch
|
||||
self.vendorBranchID = vendorBranchID
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public enum SelectRoute: Sendable {
|
||||
case employee(context: Context)
|
||||
case vendorBranches(context: Context)
|
||||
|
||||
public enum Context: String, Codable, Sendable, CaseIterable {
|
||||
case purchaseOrderForm
|
||||
case purchaseOrderSearch
|
||||
}
|
||||
|
||||
static let rootPath = "select"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.employee(context:))) {
|
||||
Path { rootPath; "employee" }
|
||||
Method.get
|
||||
Query {
|
||||
Field("context") { Context.parser() }
|
||||
}
|
||||
}
|
||||
Route(.case(Self.vendorBranches(context:))) {
|
||||
Path { rootPath; "vendor-branches" }
|
||||
Method.get
|
||||
Query {
|
||||
Field("context") { Context.parser() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum UserRoute: Sendable {
|
||||
case form
|
||||
case shared(ApiRoute.UserApiRoute)
|
||||
|
||||
static let rootPath = "users"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.form)) {
|
||||
Path { rootPath; "create" }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.shared)) {
|
||||
ApiRoute.UserApiRoute.router
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum VendorRoute: Sendable {
|
||||
case createBranch(VendorBranch.Create)
|
||||
case form
|
||||
case shared(ApiRoute.VendorApiRoute)
|
||||
|
||||
static let rootPath = "vendors"
|
||||
|
||||
public static let router = OneOf {
|
||||
Route(.case(Self.createBranch)) {
|
||||
Path { rootPath; "branches" }
|
||||
Method.post
|
||||
Body(.json(VendorBranch.Create.self))
|
||||
}
|
||||
Route(.case(Self.form)) {
|
||||
Path { rootPath; "create" }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.shared)) {
|
||||
ApiRoute.VendorApiRoute.router
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user