-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
76 lines (63 loc) · 1.71 KB
/
router.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package handlers
import (
"github.com/4lexvav/hit-the-goal/http/handlers/comments"
"github.com/4lexvav/hit-the-goal/http/handlers/lists"
"github.com/4lexvav/hit-the-goal/http/handlers/projects"
"github.com/4lexvav/hit-the-goal/http/handlers/tasks"
"github.com/4lexvav/hit-the-goal/http/middlewares"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
)
func NewRouter() *chi.Mux {
r := chi.NewRouter()
r.Use(middleware.Recoverer)
r.Use(middlewares.RequestID)
addProjectRoutes(r)
addListRoutes(r)
addTaskRoutes(r)
addCommentRoutes(r)
return r
}
func addProjectRoutes(r chi.Router) {
r.Route("/projects", func(r chi.Router) {
r.Get("/", projects.GetList)
r.Post("/", projects.Create)
r.Route("/{projectID}", func(r chi.Router) {
r.Get("/", projects.GetById)
r.Patch("/", projects.Update)
r.Delete("/", projects.Delete)
})
})
}
func addListRoutes(r chi.Router) {
r.Route("/projects/{projectID}/lists", func(r chi.Router) {
r.Get("/", lists.GetList)
r.Post("/", lists.Create)
r.Route("/{listID}", func(r chi.Router) {
r.Get("/", lists.GetById)
r.Patch("/", lists.Update)
r.Delete("/", lists.Delete)
})
})
}
func addTaskRoutes(r chi.Router) {
r.Route("/lists/{listID}/tasks", func(r chi.Router) {
r.Get("/", tasks.GetList)
r.Post("/", tasks.Create)
r.Route("/{taskID}", func(r chi.Router) {
r.Get("/", tasks.GetById)
r.Patch("/", tasks.Update)
r.Delete("/", tasks.Delete)
})
})
}
func addCommentRoutes(r chi.Router) {
r.Route("/tasks/{taskID}/comments", func(r chi.Router) {
r.Get("/", comments.GetList)
r.Post("/", comments.Create)
r.Route("/{commentID}", func(r chi.Router) {
r.Patch("/", comments.Update)
r.Delete("/", comments.Delete)
})
})
}