-
Notifications
You must be signed in to change notification settings - Fork 4
/
router.go
83 lines (71 loc) · 2.72 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
77
78
79
80
81
82
83
package main
import (
"github.com/labstack/echo-contrib/prometheus"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
// SetRouting ルーティングの設定
func SetRouting(port string) {
e := echo.New()
// Middleware
e.Use(middleware.Recover())
e.Use(middleware.Logger())
p := prometheus.NewPrometheus("echo", nil)
p.Use(e)
api := InjectAPIServer()
// Static Files
e.Static("/", "client/dist")
e.Static("/js", "client/dist/js")
e.Static("/img", "client/dist/img")
e.Static("/fonts", "client/dist/fonts")
e.Static("/css", "client/dist/css")
e.File("/app.js", "client/dist/app.js")
e.File("/favicon.ico", "client/dist/favicon.ico")
e.File("*", "client/dist/index.html")
echoAPI := e.Group("/api", api.SetValidatorMiddleware, api.SetUserIDMiddleware, api.TraPMemberAuthenticate)
{
apiQuestionnnaires := echoAPI.Group("/questionnaires")
{
apiQuestionnnaires.GET("", api.GetQuestionnaires, api.TrapRateLimitMiddlewareFunc())
apiQuestionnnaires.POST("", api.PostQuestionnaire)
apiQuestionnnaires.GET("/:questionnaireID", api.GetQuestionnaire)
apiQuestionnnaires.PATCH("/:questionnaireID", api.EditQuestionnaire, api.QuestionnaireAdministratorAuthenticate)
apiQuestionnnaires.DELETE("/:questionnaireID", api.DeleteQuestionnaire, api.QuestionnaireAdministratorAuthenticate)
apiQuestionnnaires.GET("/:questionnaireID/questions", api.GetQuestions)
apiQuestionnnaires.POST("/:questionnaireID/questions", api.PostQuestionByQuestionnaireID)
}
apiQuestions := echoAPI.Group("/questions")
{
apiQuestions.PATCH("/:questionID", api.EditQuestion, api.QuestionAdministratorAuthenticate)
apiQuestions.DELETE("/:questionID", api.DeleteQuestion, api.QuestionAdministratorAuthenticate)
}
apiResponses := echoAPI.Group("/responses")
{
apiResponses.POST("", api.PostResponse)
apiResponses.GET("/:responseID", api.GetResponse, api.ResponseReadAuthenticate)
apiResponses.PATCH("/:responseID", api.EditResponse, api.RespondentAuthenticate)
apiResponses.DELETE("/:responseID", api.DeleteResponse, api.RespondentAuthenticate)
}
apiUsers := echoAPI.Group("/users")
{
/*
TODO
apiUsers.GET("")
*/
apiUsersMe := apiUsers.Group("/me")
{
apiUsersMe.GET("", api.GetUsersMe)
apiUsersMe.GET("/responses", api.GetMyResponses)
apiUsersMe.GET("/responses/:questionnaireID", api.GetMyResponsesByID)
apiUsersMe.GET("/targeted", api.GetTargetedQuestionnaire)
apiUsersMe.GET("/administrates", api.GetMyQuestionnaire)
}
apiUsers.GET("/:traQID/targeted", api.GetTargettedQuestionnairesBytraQID)
}
apiResults := echoAPI.Group("/results")
{
apiResults.GET("/:questionnaireID", api.GetResults, api.ResultAuthenticate)
}
}
e.Logger.Fatal(e.Start(port))
}