feat: Working on route and id helpers for views.

This commit is contained in:
2025-01-17 23:50:04 -05:00
parent 531a385dba
commit d8328314ed
21 changed files with 585 additions and 255 deletions

View File

@@ -11,28 +11,44 @@ struct UtilsViewController: RouteCollection {
let route = routes.protected
route.group("select") {
$0.get("employee", use: employeeSelect(req:))
$0.get("vendor-branches", use: vendorBranchSelect(req:))
}
}
@Sendable
func employeeSelect(req: Request) async throws -> HTMLResponse {
let context = try req.query.decode(EmployeeSelectContext.self)
let context = try req.query.decode(SelectQueryContext.self)
let employees = try await database.employees.fetchAll()
return await req.render { context.toHTML(employees: employees) }
}
@Sendable
func vendorBranchSelect(req: Request) async throws -> HTMLResponse {
let context = try req.query.decode(SelectQueryContext.self)
let branches = try await database.vendorBranches.fetchAllWithDetail()
return await req.render { context.toHTML(branches: branches) }
}
}
private struct EmployeeSelectContext: Content {
private struct SelectQueryContext: Content {
let context: EmployeeSelect.Context
let context: SelectContext
func toHTML(employees: [Employee]) -> EmployeeSelect {
switch context {
case .form:
case .purchaseOrderForm:
return .purchaseOrderForm(employees: employees)
case .search:
case .purchaseOrderSearch:
return .purchaseOrderSearch(employees: employees)
}
}
func toHTML(branches: [VendorBranch.Detail]) -> VendorBranchSelect {
switch context {
case .purchaseOrderForm:
return .purchaseOrderForm(branches: branches)
case .purchaseOrderSearch:
return .purchaseOrderSearch(branches: branches)
}
}
}