feat: Removes base routes and goes back to separated routes.

This commit is contained in:
2025-01-22 08:45:04 -05:00
parent eb1e27e03a
commit c74433c2eb
8 changed files with 215 additions and 390 deletions

View File

@@ -36,77 +36,188 @@ public enum ApiRoute: Sendable, Equatable {
}
public enum EmployeeRoute: Sendable, Equatable {
case base(BaseRoute.EmployeeRoute)
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.base)) {
BaseRoute.EmployeeRoute.router
Route(.case(Self.create)) {
Path { rootPath }
Method.post
Body(.json(Employee.Create.self))
}
Route(.case(Self.delete(id:))) {
Path { BaseRoute.EmployeeRoute.rootPath; Employee.ID.parser() }
Path { rootPath; Employee.ID.parser() }
Method.delete
}
Route(.case(Self.index)) {
Path { rootPath }
Method.get
}
Route(.case(Self.get(id:))) {
Path { rootPath; Employee.ID.parser() }
Method.get
}
Route(.case(Self.update(id:updates:))) {
Path { rootPath; Employee.ID.parser() }
Method.put
Body(.json(Employee.Update.self))
}
}
}
public enum PurchaseOrderRoute: Sendable, Equatable {
case base(BaseRoute.PurchaseOrderRoute)
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.base)) {
BaseRoute.PurchaseOrderRoute.router
Route(.case(Self.create)) {
Path { rootPath }
Method.post
Body(.json(PurchaseOrder.Create.self))
}
Route(.case(Self.delete(id:))) {
Path { BaseRoute.PurchaseOrderRoute.rootPath; PurchaseOrder.ID.parser() }
Path { rootPath; PurchaseOrder.ID.parser() }
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 UserRoute: Sendable, Equatable {
case base(BaseRoute.UserRoute)
case delete(id: User.ID)
case create(User.Create)
case get(id: User.ID)
case index
case update(id: User.ID, updates: User.Update)
static let rootPath = "users"
public static let router = OneOf {
Route(.case(Self.base)) {
BaseRoute.UserRoute.router
Route(.case(Self.create)) {
Path { rootPath }
Method.post
Body(.json(User.Create.self))
}
Route(.case(Self.delete(id:))) {
Path { BaseRoute.UserRoute.rootPath; User.ID.parser() }
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 VendorRoute: Sendable, Equatable {
case base(BaseRoute.VendorRoute)
case delete(id: Vendor.ID)
case index(withBranches: Bool? = nil)
case create(Vendor.Create)
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.base)) {
BaseRoute.VendorRoute.router
}
Route(.case(Self.delete(id:))) {
Path { BaseRoute.VendorRoute.rootPath; Vendor.ID.parser() }
Path { rootPath; Vendor.ID.parser() }
Method.delete
}
Route(.case(Self.create)) {
Path { rootPath }
Method.post
Body(.json(Vendor.Create.self))
}
Route(.case(Self.get(id:))) {
Path { rootPath; Vendor.ID.parser() }
Method.get
}
Route(.case(Self.index(withBranches:))) {
Path { rootPath }
Method.get
Query {
Optionally {
Field("branches", default: nil) {
Bool.parser()
}
}
}
}
Route(.case(Self.update(id:updates:))) {
Path { rootPath; Vendor.ID.parser() }
Method.put
Body(.json(Vendor.Update.self))
}
}
}
public enum VendorBranchRoute: Sendable, Equatable {
case base(BaseRoute.VendorBranchRoute)
case delete(id: VendorBranch.ID)
case create(VendorBranch.Create)
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.base)) {
BaseRoute.VendorBranchRoute.router
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 {
Optionally { Field("vendorID", default: nil) { VendorBranch.ID.parser() } }
}
}
Route(.case(Self.update(id:updates:))) {
Path { "vendors"; "branches"; VendorBranch.ID.parser() }
Method.put
Body(.json(VendorBranch.Update.self))
}
}
}
}