blob: 3c86b8c647772d152eec6c98d5d976e3ed2d2b10 (
plain)
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
|
package router
import (
"github.com/gin-gonic/gin"
"water/api/internal/controllers"
"water/api/internal/middleware"
)
func SetupRouter() *gin.Engine {
// Disable Console Color
// gin.DisableConsoleColor()
r := gin.Default()
r.Use(middleware.CORSMiddleware())
r.Use(gin.Logger())
r.Use(gin.Recovery())
api := r.Group("api/v1")
api.POST("/auth", controllers.AuthHandler)
api.GET("/sizes", middleware.TokenRequired(), controllers.GetSizes)
api.PATCH("/user/preferences", controllers.UpdateUserPreferences)
user := api.Group("/user/:id")
user.Use(middleware.TokenRequired())
{
user.GET("", controllers.GetUser)
user.GET("preferences", controllers.GetUserPreferences)
}
stats := api.Group("/stats")
stats.Use(middleware.TokenRequired())
{
stats.GET("/", controllers.GetAllStatistics)
stats.POST("/", controllers.PostNewStatistic)
stats.GET("weekly/", controllers.GetWeeklyStatistics)
stats.GET("daily/", controllers.GetDailyUserStatistics)
stats.GET("user/:uuid", controllers.GetUserStatistics)
stats.PATCH("user/:uuid", controllers.UpdateUserStatistic)
stats.DELETE("user/:uuid", controllers.DeleteUserStatistic)
}
return r
}
|