package api

import (
	"gxt-file-server/pkg/middleware"
	"gxt-file-server/router/api/controllers"

	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"go.uber.org/dig"
)

// RegisterRouters 注册路由
func RegisterRouters(s *ghttp.Server, container *dig.Container) error {
	controllers.Inject(container)
	// 路由根
	gr := s.Group(g.Cfg().GetString("server.RoutePrefix")).
		Group("/api")
	// 注册请求限制中间件
	//gr.Middleware(middleware.RateLimiterMiddleware())
	gr.Middleware(middleware.CROSMiddleWare())
	return container.Invoke(func(
		cDemo *controllers.Demo,
		cFile *controllers.File,
	) {
		v1 := gr.Group("/v1")
		{
			gDemo := v1.Group("/demos")
			{
				gDemo.POST("/", cDemo.Create)
			}
			gFile := v1.Group("/files")
			{
				gFile.POST("/", cFile.Upload)
				gFile.GET("/", cFile.Download)
				gFile.PUT("/persistent", cFile.Persistent)
				gFile.POST("/chunk", cFile.Chunk)
				gFile.POST("/merge", cFile.Merge)
			}
		}
	})
}
