diff options
Diffstat (limited to 'api/internal/router/router.go')
-rw-r--r-- | api/internal/router/router.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/api/internal/router/router.go b/api/internal/router/router.go new file mode 100644 index 0000000..adf96d0 --- /dev/null +++ b/api/internal/router/router.go | |||
@@ -0,0 +1,42 @@ | |||
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 | |||
21 | user := api.Group("/user/:uuid") | ||
22 | user.Use(middleware.TokenRequired()) | ||
23 | { | ||
24 | user.GET("", controllers.GetUser) | ||
25 | user.GET("preferences", controllers.GetUserPreferences) | ||
26 | user.PATCH("preferences", controllers.UpdateUserPreferences) | ||
27 | } | ||
28 | |||
29 | stats := api.Group("/stats") | ||
30 | stats.Use(middleware.TokenRequired()) | ||
31 | { | ||
32 | stats.GET("/", controllers.GetAllStatistics) | ||
33 | stats.POST("/", controllers.PostNewStatistic) | ||
34 | stats.GET("weekly/", controllers.GetWeeklyStatistics) | ||
35 | stats.GET("daily/", controllers.GetDailyUserStatistics) | ||
36 | stats.GET("user/:uuid", controllers.GetUserStatistics) | ||
37 | stats.PATCH("user/:uuid", controllers.UpdateUserStatistic) | ||
38 | stats.DELETE("user/:uuid", controllers.DeleteUserStatistic) | ||
39 | } | ||
40 | |||
41 | return r | ||
42 | } \ No newline at end of file | ||