first commit
This commit is contained in:
95
routers/router.go
Normal file
95
routers/router.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package routers
|
||||
|
||||
import (
|
||||
"ginimageApi/app/accounts/handlers"
|
||||
blogHandlers "ginimageApi/app/blogs/handlers"
|
||||
imageHandlers "ginimageApi/app/images/handlers"
|
||||
"ginimageApi/app/mcp"
|
||||
"ginimageApi/app/middleware"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
swaggerFiles "github.com/swaggo/files"
|
||||
ginSwagger "github.com/swaggo/gin-swagger"
|
||||
)
|
||||
|
||||
func Setup(r *gin.Engine) {
|
||||
r.StaticFile("/", "./static/index.html")
|
||||
r.Static("/static", "./static")
|
||||
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
c.JSON(404, gin.H{
|
||||
"error": "endpoint bulunamadı",
|
||||
"path": c.Request.URL.Path,
|
||||
"method": c.Request.Method,
|
||||
"docs": "/swagger/index.html",
|
||||
"api_base": "/api/v1",
|
||||
})
|
||||
})
|
||||
|
||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
r.Static("/uploads", "./uploads")
|
||||
|
||||
|
||||
api := r.Group("/api/v1")
|
||||
|
||||
publicAuth := api.Group("/auth")
|
||||
{
|
||||
publicAuth.POST("/register", handlers.Register)
|
||||
publicAuth.POST("/login", handlers.Login)
|
||||
publicAuth.POST("/refresh", handlers.Refresh)
|
||||
publicAuth.GET("/verify-email", handlers.VerifyEmail)
|
||||
publicAuth.POST("/social/google", handlers.GoogleLogin)
|
||||
publicAuth.POST("/social/github", handlers.GitHubLogin)
|
||||
}
|
||||
|
||||
publicBlogs := api.Group("/blogs")
|
||||
{
|
||||
publicBlogs.GET("", blogHandlers.ListPosts)
|
||||
publicBlogs.GET("/categories", blogHandlers.ListCategories)
|
||||
publicBlogs.GET("/categories/:slug", blogHandlers.GetCategory)
|
||||
publicBlogs.GET("/tags", blogHandlers.ListTags)
|
||||
publicBlogs.GET("/tags/:slug", blogHandlers.GetTag)
|
||||
publicBlogs.GET("/:slug", blogHandlers.GetPost)
|
||||
}
|
||||
|
||||
protected := api.Group("")
|
||||
protected.Use(middleware.AuthRequired())
|
||||
{
|
||||
protected.GET("/me", handlers.Me)
|
||||
protected.GET("/me/profile", handlers.GetMyProfile)
|
||||
protected.PUT("/me/profile", handlers.UpdateMyProfile)
|
||||
protected.POST("/images/process", imageHandlers.Process)
|
||||
protected.GET("/images", imageHandlers.ListImages)
|
||||
protected.GET("/images/:id", imageHandlers.GetImage)
|
||||
}
|
||||
|
||||
admin := api.Group("")
|
||||
admin.Use(middleware.AuthRequired(), middleware.AdminRequired())
|
||||
{
|
||||
admin.POST("/admin/tokens/issue", handlers.IssueAdminScopedToken)
|
||||
admin.GET("/admin/users", handlers.ListAdminUsers)
|
||||
admin.GET("/admin/users/:id", handlers.GetAdminUser)
|
||||
admin.POST("/admin/users", handlers.CreateAdminUser)
|
||||
admin.PUT("/admin/users/:id", handlers.UpdateAdminUser)
|
||||
admin.PATCH("/admin/users/:id/status", handlers.UpdateAdminUserStatus)
|
||||
admin.GET("/admin/users/:id/profile", handlers.GetAdminUserProfile)
|
||||
admin.PUT("/admin/users/:id/profile", handlers.UpdateAdminUserProfile)
|
||||
admin.DELETE("/admin/users/:id", handlers.DeleteAdminUser)
|
||||
|
||||
admin.POST("/users/:id/admin", handlers.MakeAdmin)
|
||||
admin.POST("/blogs", blogHandlers.CreatePost)
|
||||
admin.PUT("/blogs/:id", blogHandlers.UpdatePost)
|
||||
admin.DELETE("/blogs/:id", blogHandlers.DeletePost)
|
||||
admin.POST("/blogs/categories", blogHandlers.CreateCategory)
|
||||
admin.PUT("/blogs/categories/:id", blogHandlers.UpdateCategory)
|
||||
admin.DELETE("/blogs/categories/:id", blogHandlers.DeleteCategory)
|
||||
admin.POST("/blogs/tags", blogHandlers.CreateTag)
|
||||
admin.PUT("/blogs/tags/:id", blogHandlers.UpdateTag)
|
||||
admin.DELETE("/blogs/tags/:id", blogHandlers.DeleteTag)
|
||||
|
||||
admin.DELETE("/mcp", mcp.StreamableHTTPDELETEHandler())
|
||||
admin.POST("/mcp/guides/upload", mcp.UploadGuideHandler())
|
||||
admin.POST("/mcp", mcp.HTTPHandler())
|
||||
admin.GET("/mcp", mcp.StreamableHTTPGETHandler())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user