diff options
| author | zberwaldt <17715430+zberwaldt@users.noreply.github.com> | 2024-03-15 22:03:11 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-15 22:03:11 -0400 |
| commit | 6f8cfbd6cc3d5adbda38e74013c68e3d4745766d (patch) | |
| tree | b3f045cd06d6622e23441b442e8f3861050ed444 /api/internal/router | |
| parent | fac21fa0a72d4a7f1a01ccd44e3acf9c90fd95bd (diff) | |
| parent | fd1332a3df191577e91c6d846a8b5db1747099fd (diff) | |
Merge pull request #1 from zberwaldt/staging
Staging to Prod
Diffstat (limited to 'api/internal/router')
| -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 | ||
