so I am trying to refactor my route definitions in Javalin to be a little more DRY.
So I have the same set of actions performed at different hierarchies. I have a company, an application, and a environment and for each of these, I've split into separate routes that use the same controller action in Javalin.
Currently, it looks a little something like this:
app.routes {
path("api/") {
path("company/{companyId}") {
path("application/{applicationId}") {
path("project/{environmentId}") {
path("doThingA") {
post(controller::doThingA)
}
path("doThingB") {
post(controller::doThingB)
}
}
path("doThingA") {
post(controller::doThingA)
}
path("doThingB") {
post(controller::doThingB)
}
}
path("doThingA") {
post(controller::doThingA)
}
path("doThingB") {
post(controller::doThingB)
}
}
}
}
Now, this seems a little messy. Anytime I want to update the action for a given route, I have to do it three times. Ideally, I'd be looking for something like:
sharedRoutes = routes {
path("doThingA") {
post(controller::doThingA)
}
path("doThingB") {
post(controller::doThingB)
}
}
app.routes {
path("api/") {
path("company/{companyId}") {
path("application/{applicationId}") {
path("project/{environmentId}") { sharedRoutes }
sharedRoutes
}
sharedRoutes
}
}
}
I know this above code is wrong but I hope it illustrates what I am trying to achieve.