package handlers import ( "database/sql" "gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/internal/auth" "gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/internal/repositories" "github.com/gin-gonic/gin" ) func Register(router *gin.Engine, db *sql.DB) { handler_posts := NewPostHandlers(repositories.NewPostRepository(db)) handler_auth := NewAuthHandlers(repositories.NewAuthRepository(db)) handler_static := NewStaticHandlers() router.GET("/health", func(c *gin.Context) { c.Status(200) }) v1 := router.Group("api/v1") v1.Static("/uploads", "/data/uploads") v1.POST("/upload", auth.JWTMiddleware(), auth.RequireAdmin(), handler_static.PostStatic) v1.GET("/upload/:file", handler_static.GetStatic) v1.GET("/callback/github", handler_auth.CallbackGithub) v1.GET("/auth/github", handler_auth.LoginGithub) v1.GET("/session", auth.JWTMiddleware(), handler_auth.GetSession) posts := v1.Group("posts") { posts.GET("/", handler_posts.GetPosts) posts.GET("/:id", handler_posts.GetPost) posts.POST("/", auth.JWTMiddleware(), auth.RequireAdmin(), handler_posts.CreatePost) posts.PUT("/:id", auth.JWTMiddleware(), auth.RequireAdmin(), handler_posts.UpdatePost) posts.DELETE("/:id", auth.JWTMiddleware(), auth.RequireAdmin(), handler_posts.DeletePost) } }