first commit

This commit is contained in:
Beyhan Oğur
2026-04-26 21:40:14 +03:00
commit e04ba85564
129 changed files with 17541 additions and 0 deletions

95
routers/router.go Normal file
View 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())
}
}

62
routers/router_test.go Normal file
View File

@@ -0,0 +1,62 @@
package routers
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
)
func TestSetupRegistersCoreRoutes(t *testing.T) {
gin.SetMode(gin.TestMode)
r := gin.New()
Setup(r)
cases := []struct {
method string
path string
}{
{method: http.MethodGet, path: "/swagger/index.html"},
{method: http.MethodPost, path: "/api/v1/auth/register"},
{method: http.MethodPost, path: "/api/v1/auth/login"},
{method: http.MethodPost, path: "/api/v1/auth/refresh"},
{method: http.MethodGet, path: "/api/v1/auth/verify-email"},
{method: http.MethodPost, path: "/api/v1/auth/social/google"},
{method: http.MethodPost, path: "/api/v1/auth/social/github"},
{method: http.MethodGet, path: "/api/v1/blogs"},
{method: http.MethodGet, path: "/api/v1/blogs/categories"},
{method: http.MethodGet, path: "/api/v1/blogs/categories/genel"},
{method: http.MethodGet, path: "/api/v1/blogs/tags"},
{method: http.MethodGet, path: "/api/v1/blogs/tags/go"},
{method: http.MethodGet, path: "/api/v1/blogs/test-slug"},
{method: http.MethodGet, path: "/api/v1/me"},
{method: http.MethodGet, path: "/api/v1/me/profile"},
{method: http.MethodPut, path: "/api/v1/me/profile"},
{method: http.MethodPost, path: "/api/v1/images/process"},
{method: http.MethodGet, path: "/api/v1/images"},
{method: http.MethodGet, path: "/api/v1/images/1"},
{method: http.MethodPost, path: "/api/v1/blogs"},
{method: http.MethodPut, path: "/api/v1/blogs/1"},
{method: http.MethodDelete, path: "/api/v1/blogs/1"},
{method: http.MethodPost, path: "/api/v1/blogs/categories"},
{method: http.MethodPut, path: "/api/v1/blogs/categories/1"},
{method: http.MethodDelete, path: "/api/v1/blogs/categories/1"},
{method: http.MethodPost, path: "/api/v1/blogs/tags"},
{method: http.MethodPut, path: "/api/v1/blogs/tags/1"},
{method: http.MethodDelete, path: "/api/v1/blogs/tags/1"},
{method: http.MethodGet, path: "/api/v1/admin/users/1/profile"},
{method: http.MethodPut, path: "/api/v1/admin/users/1/profile"},
}
for _, tc := range cases {
req := httptest.NewRequest(tc.method, tc.path, nil)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
if w.Code == http.StatusNotFound {
t.Fatalf("expected route %s %s to be registered", tc.method, tc.path)
}
}
}