diff options
Diffstat (limited to 'api/internal/router/router.go')
-rw-r--r-- | api/internal/router/router.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/api/internal/router/router.go b/api/internal/router/router.go new file mode 100644 index 0000000..a71c3e6 --- /dev/null +++ b/api/internal/router/router.go | |||
@@ -0,0 +1,43 @@ | |||
1 | package router | ||
2 | |||
3 | import ( | ||
4 | "github.com/gin-gonic/gin" | ||
5 | "water/api/internal/controllers" | ||
6 | "water/api/internal/middleware" | ||
7 | ) | ||
8 | |||
9 | func SetupRouter() *gin.Engine { | ||
10 | // Disable Console Color | ||
11 | // gin.DisableConsoleColor() | ||
12 | r := gin.Default() | ||
13 | r.Use(middleware.CORSMiddleware()) | ||
14 | r.Use(gin.Logger()) | ||
15 | r.Use(gin.Recovery()) | ||
16 | |||
17 | api := r.Group("api/v1") | ||
18 | |||
19 | api.POST("/auth", controllers.AuthHandler) | ||
20 | api.GET("/sizes", middleware.TokenRequired(), controllers.GetSizes) | ||
21 | api.PATCH("/user/preferences", controllers.UpdateUserPreferences) | ||
22 | |||
23 | user := api.Group("/user/:id") | ||
24 | user.Use(middleware.TokenRequired()) | ||
25 | { | ||
26 | user.GET("", controllers.GetUser) | ||
27 | user.GET("preferences", controllers.GetUserPreferences) | ||
28 | } | ||
29 | |||
30 | stats := api.Group("/stats") | ||
31 | stats.Use(middleware.TokenRequired()) | ||
32 | { | ||
33 | stats.GET("", controllers.GetAllStatistics) | ||
34 | stats.POST("", controllers.PostNewStatistic) | ||
35 | stats.GET("weekly", controllers.GetWeeklyStatistics) | ||
36 | stats.GET("daily", controllers.GetDailyUserStatistics) | ||
37 | stats.GET("user/:uuid", controllers.GetUserStatistics) | ||
38 | stats.PATCH("user/:uuid", controllers.UpdateUserStatistic) | ||
39 | stats.DELETE("user/:uuid", controllers.DeleteUserStatistic) | ||
40 | } | ||
41 | |||
42 | return r | ||
43 | } \ No newline at end of file | ||