Maxim Slipenko
db49ea2c51
All checks were successful
Format and Lint / format-check (push) Successful in 14m34s
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package router
|
|
|
|
import (
|
|
"github.com/go-chi/chi/v5"
|
|
httpSwagger "github.com/swaggo/http-swagger"
|
|
|
|
docs "code.alt-gnome.ru/aides-infra/aides-repo-api/docs"
|
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config"
|
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/controllers/taskcontroller"
|
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/logger"
|
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/middlewares"
|
|
)
|
|
|
|
type Router struct {
|
|
config *config.Config
|
|
taskController *taskcontroller.TaskController
|
|
}
|
|
|
|
func New(
|
|
config *config.Config,
|
|
taskController *taskcontroller.TaskController,
|
|
) *Router {
|
|
return &Router{
|
|
config: config,
|
|
taskController: taskController,
|
|
}
|
|
}
|
|
|
|
func (r *Router) Setup() *chi.Mux {
|
|
authGuard := middlewares.CreateAuthGuard(r.config)
|
|
logger := middlewares.LoggerMiddleware(logger.GetLogger())
|
|
|
|
router := chi.NewRouter()
|
|
router.Use(logger)
|
|
|
|
docs.SwaggerInfo.Version = config.Version
|
|
|
|
router.Get("/swagger/*", httpSwagger.WrapHandler)
|
|
|
|
router.Route("/tasks", func(taskRouter chi.Router) {
|
|
taskRouter.With(authGuard).Post("/", r.taskController.Create)
|
|
taskRouter.Route("/{taskID}", func(sTaskRouter chi.Router) {
|
|
sTaskRouter.With(authGuard).Post("/upload", r.taskController.Upload)
|
|
})
|
|
})
|
|
|
|
return router
|
|
}
|