feat: Refactoring route declarations.

This commit is contained in:
2025-01-19 10:52:15 -05:00
parent d27a19863a
commit 1c8748211c
20 changed files with 954 additions and 644 deletions

View File

@@ -19,7 +19,7 @@ struct EmployeeForm: HTML {
var content: some HTML {
Float(shouldDisplay: shouldShow, resetURL: "/employees") {
form(
employee == nil ? .hx.post(targetURL) : .hx.put(targetURL),
employee == nil ? .hx.post(route: targetURL) : .hx.put(route: targetURL),
.hx.target(target),
employee == nil
? .hx.swap(.beforeEnd.transition(true).swap("0.5s"))
@@ -51,7 +51,7 @@ struct EmployeeForm: HTML {
"Delete"
}
.attributes(
.hx.delete("/api/v1/employees/\(employee.id)"),
.hx.delete(route: .employee(.shared(.delete(id: employee.id)))),
.hx.confirm("Are you sure you want to delete this employee?"),
.hx.target("#employee_\(employee.id)"),
.hx.swap(.outerHTML.transition(true).swap("1s"))
@@ -74,8 +74,8 @@ struct EmployeeForm: HTML {
return "Update"
}
private var targetURL: String {
guard let employee else { return "/employees" }
return "/employees/\(employee.id)"
private var targetURL: SharedModels.ViewRoute {
guard let employee else { return .employee(.shared(.index)) }
return .employee(.shared(.get(id: employee.id)))
}
}

View File

@@ -14,7 +14,7 @@ struct EmployeeTable: HTML {
Button.add()
.attributes(
.style("padding: 0px 10px;"),
.hx.get(route: .employees(.create)),
.hx.get(route: .employee(.shared(.index))),
.hx.target(.float),
.hx.swap(.outerHTML.transition(true).swap("0.5s"))
)
@@ -39,7 +39,7 @@ struct EmployeeTable: HTML {
Button.detail()
.attributes(
.style("padding-left: 15px;"),
.hx.get(route: .employees(.id(employee.id))),
.hx.get(route: .employee(.shared(.get(id: employee.id)))),
.hx.target(.float),
.hx.pushURL(true),
.hx.swap(.outerHTML.transition(true).swap("0.5s"))