teldrive/routes/user.go

99 lines
1.7 KiB
Go
Raw Normal View History

2023-08-17 19:32:27 +08:00
package routes
import (
2023-09-20 03:20:44 +08:00
"net/http"
"github.com/divyam234/teldrive/database"
2023-08-17 19:32:27 +08:00
"github.com/divyam234/teldrive/services"
"github.com/gin-gonic/gin"
)
func addUserRoutes(rg *gin.RouterGroup) {
r := rg.Group("/users")
r.Use(Authmiddleware)
2023-09-20 03:20:44 +08:00
userService := services.UserService{Db: database.DB}
2023-08-17 19:32:27 +08:00
r.GET("/profile", func(c *gin.Context) {
if c.Query("photo") != "" {
userService.GetProfilePhoto(c)
}
})
2023-09-20 03:20:44 +08:00
r.GET("/stats", func(c *gin.Context) {
res, err := userService.Stats(c)
if err != nil {
c.AbortWithError(err.Code, err.Error)
return
}
c.JSON(http.StatusOK, res)
})
r.GET("/bots", func(c *gin.Context) {
res, err := userService.GetBots(c)
if err != nil {
c.AbortWithError(err.Code, err.Error)
return
}
c.JSON(http.StatusOK, res)
})
r.GET("/channels", func(c *gin.Context) {
res, err := userService.ListChannels(c)
if err != nil {
c.AbortWithError(err.Code, err.Error)
return
}
c.JSON(http.StatusOK, res)
})
r.PATCH("/channels", func(c *gin.Context) {
res, err := userService.UpdateChannel(c)
if err != nil {
c.AbortWithError(err.Code, err.Error)
return
}
c.JSON(http.StatusOK, res)
})
r.POST("/bots", func(c *gin.Context) {
res, err := userService.AddBots(c)
if err != nil {
c.AbortWithError(err.Code, err.Error)
return
}
c.JSON(http.StatusCreated, res)
})
r.GET("/bots/revoke", func(c *gin.Context) {
res, err := userService.RevokeBotSession(c)
if err != nil {
c.AbortWithError(err.Code, err.Error)
return
}
c.JSON(http.StatusOK, res)
})
r.DELETE("/cache", func(c *gin.Context) {
res, err := userService.ClearCache(c)
if err != nil {
c.AbortWithError(err.Code, err.Error)
return
}
c.JSON(http.StatusOK, res)
})
2023-08-17 19:32:27 +08:00
}