Files
evanpage/backend/internal/router/router.go
root 832512469a backend: expand bookmark API with bulk ops and metadata fetcher
- bulk create/delete/move, reorder, rename-category endpoints
- /bookmarks/meta with SSRF-safe fetcher (blocks private/loopback IPs,
  8s timeout, 1 MiB body cap)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-02 22:52:43 +00:00

56 lines
1.8 KiB
Go

package router
import (
"evanpage-backend/internal/config"
"evanpage-backend/internal/db"
"evanpage-backend/internal/handler"
"evanpage-backend/internal/middleware"
"evanpage-backend/internal/repository"
"evanpage-backend/internal/service"
"github.com/gin-gonic/gin"
)
func Setup(cfg *config.Config) *gin.Engine {
r := gin.New()
r.Use(middleware.Logger())
r.Use(middleware.CORS())
r.Use(gin.Recovery())
userRepo := repository.NewUserRepository(db.DB)
userService := service.NewUserService(userRepo)
bookmarkRepo := repository.NewBookmarkRepository(db.DB)
bookmarkService := service.NewBookmarkService(bookmarkRepo)
authHandler := handler.NewAuthHandler(userService)
healthHandler := handler.NewHealthHandler(db.DB)
bookmarkHandler := handler.NewBookmarkHandler(bookmarkService, userService)
// Public routes
r.POST("/api/auth/local-login", authHandler.LocalLogin)
r.POST("/api/auth/lookup-binding", authHandler.LookupBinding)
r.POST("/api/auth/bind-keycloak", authHandler.BindKeycloak)
r.POST("/api/auth/init", authHandler.InitAdmin)
r.GET("/api/health", healthHandler.Check)
r.GET("/api/bookmarks/public", bookmarkHandler.PublicList)
// Authenticated routes
auth := r.Group("/api")
auth.Use(middleware.AuthProxy())
{
auth.GET("/bookmarks", bookmarkHandler.List)
auth.POST("/bookmarks", bookmarkHandler.Create)
auth.POST("/bookmarks/meta", bookmarkHandler.FetchMeta)
auth.POST("/bookmarks/bulk", bookmarkHandler.BulkCreate)
auth.POST("/bookmarks/bulk-delete", bookmarkHandler.BulkDelete)
auth.POST("/bookmarks/bulk-move", bookmarkHandler.BulkMove)
auth.POST("/bookmarks/reorder", bookmarkHandler.Reorder)
auth.POST("/bookmarks/rename-category", bookmarkHandler.RenameCategory)
auth.PUT("/bookmarks/:id", bookmarkHandler.Update)
auth.DELETE("/bookmarks/:id", bookmarkHandler.Delete)
}
return r
}