feat: Cleans up routes.
This commit is contained in:
@@ -38,37 +38,137 @@ public enum ApiRoute: Sendable {
|
||||
}
|
||||
|
||||
public enum EmployeeApiRoute: Sendable {
|
||||
case shared(SharedEmployeeRoute)
|
||||
case create(Employee.Create)
|
||||
case delete(id: Employee.ID)
|
||||
case get(id: Employee.ID)
|
||||
case index
|
||||
case update(id: Employee.ID, updates: Employee.Update)
|
||||
|
||||
public static let router = Route(.case(Self.shared)) {
|
||||
SharedEmployeeRoute.router
|
||||
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 shared(SharedPurchaseOrderRoute)
|
||||
case create(PurchaseOrder.Create)
|
||||
case delete(id: PurchaseOrder.ID)
|
||||
case get(id: PurchaseOrder.ID)
|
||||
case index
|
||||
case page(page: Int, limit: Int)
|
||||
|
||||
public static let router = Route(.case(Self.shared)) {
|
||||
SharedPurchaseOrderRoute.router
|
||||
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.
|
||||
// TODO: Add login / logout.
|
||||
public enum UserApiRoute: Sendable {
|
||||
case shared(SharedUserRoute)
|
||||
case create(User.Create)
|
||||
case delete(id: User.ID)
|
||||
case get(id: User.ID)
|
||||
case index
|
||||
case update(id: User.ID, updates: User.Update)
|
||||
|
||||
public static let router = Route(.case(Self.shared)) {
|
||||
SharedUserRoute.router
|
||||
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.update(id:updates:))) {
|
||||
Path { rootPath; User.ID.parser() }
|
||||
Method.patch
|
||||
Body(.json(User.Update.self))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum VendorApiRoute: Sendable {
|
||||
case index(withBranches: Bool?)
|
||||
case shared(SharedVendorRoute)
|
||||
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.index(withBranches:))) {
|
||||
Path { rootPath }
|
||||
Method.get
|
||||
@@ -78,19 +178,32 @@ public enum ApiRoute: Sendable {
|
||||
}
|
||||
}
|
||||
}
|
||||
Route(.case(Self.shared)) {
|
||||
SharedVendorRoute.router
|
||||
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 shared(SharedVendorBranchRoute)
|
||||
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
|
||||
@@ -102,9 +215,6 @@ public enum ApiRoute: Sendable {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user