Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update routes file when coast gen route is called #89

Closed
swlkr opened this issue Oct 3, 2019 · 4 comments
Closed

Update routes file when coast gen route is called #89

swlkr opened this issue Oct 3, 2019 · 4 comments
Assignees

Comments

@swlkr
Copy link
Member

swlkr commented Oct 3, 2019

Right now you have to manually update the routes.clj file, that stinks.

Ideally, coast would just insert the new default routes when coast gen route todo is run.

(ns routes
  (:require [coast :refer [routes middleware]
            [routes.home :as home]
+           [routes.todo :as todo]))

(def home-routes
  (routes
    [:get "/" home/index]))

+(def todo-routes
+  (routes
+    [:get "/todo" index]
+    [:get "/todo/build" build]
+    [:post "/todo" create]

+   (middleware todo/set-todo
+      [:get "/todo/:id" show]
+      [:get "/todo/:id/edit" edit]
+      [:patch "/todo/:id" patch]
+      [:delete "/todo/:id" delete])))

(def app
  (routes
    home-routes
+   todo-routes))

Kind of related to #87 but much smaller in scope

@swlkr swlkr self-assigned this Oct 3, 2019
@swlkr
Copy link
Member Author

swlkr commented Oct 3, 2019

This is pretty much the main blocker before next is merged into master and then from there I'll work on updating the docs

@dawranliou
Copy link
Member

I'm more inclined to adding the routes.todo inside todo-routes:

(ns routes.todo
  (:require [coast :refer [routes]))

(def todo-routes
  (routes
    [:get "/todo" index]
    [:get "/todo/build" build]
    [:post "/todo" create]

   (middleware todo/set-todo
      [:get "/todo/:id" show]
      [:get "/todo/:id/edit" edit]
      [:patch "/todo/:id" patch]
      [:delete "/todo/:id" delete])))

And add the todo-routes into the app manually:

(ns routes
  (:require [coast :refer [routes middleware]
            [routes.home :as home]
            [routes.todo :refer [todo-routes]]))

(def app
  (routes
    home-routes
    todo-routes))

The reason is that I don't always need to include the whote routes into the app. Also, this seems a lot easier to implement 😛

@swlkr
Copy link
Member Author

swlkr commented Oct 4, 2019

It's funny you mention that, because that's what the next branch does now, in that case, I'll leave it and I mean if you want all of the routes in one file, you can put them there, it just won't happen by default

@swlkr swlkr closed this as completed Oct 4, 2019
@dawranliou
Copy link
Member

🙌 🙌 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants