2024-12-04 11:46:42 +00:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
2024-12-12 13:27:07 +00:00
|
|
|
"github.com/go-chi/chi/v5"
|
2024-12-14 08:40:45 +00:00
|
|
|
httpSwagger "github.com/swaggo/http-swagger"
|
2024-12-04 11:46:42 +00:00
|
|
|
|
2024-12-17 15:48:10 +00:00
|
|
|
docs "code.alt-gnome.ru/aides-infra/aides-repo-api/docs"
|
2024-12-15 06:16:51 +00:00
|
|
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config"
|
2024-12-12 13:27:07 +00:00
|
|
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/controllers/taskcontroller"
|
2024-12-16 16:34:51 +00:00
|
|
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/logger"
|
2024-12-12 13:27:07 +00:00
|
|
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/middlewares"
|
2024-12-04 11:46:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Router struct {
|
2024-12-15 06:16:51 +00:00
|
|
|
config *config.Config
|
|
|
|
taskController *taskcontroller.TaskController
|
2024-12-04 11:46:42 +00:00
|
|
|
}
|
|
|
|
|
2024-12-15 06:16:51 +00:00
|
|
|
func New(
|
|
|
|
config *config.Config,
|
|
|
|
taskController *taskcontroller.TaskController,
|
|
|
|
) *Router {
|
2024-12-12 13:27:07 +00:00
|
|
|
return &Router{
|
2024-12-15 06:16:51 +00:00
|
|
|
config: config,
|
|
|
|
taskController: taskController,
|
2024-12-12 13:27:07 +00:00
|
|
|
}
|
2024-12-04 11:46:42 +00:00
|
|
|
}
|
|
|
|
|
2024-12-12 13:27:07 +00:00
|
|
|
func (r *Router) Setup() *chi.Mux {
|
2024-12-15 06:16:51 +00:00
|
|
|
authGuard := middlewares.CreateAuthGuard(r.config)
|
2024-12-16 16:34:51 +00:00
|
|
|
logger := middlewares.LoggerMiddleware(logger.GetLogger())
|
|
|
|
|
|
|
|
router := chi.NewRouter()
|
|
|
|
router.Use(logger)
|
2024-12-14 08:35:45 +00:00
|
|
|
|
2024-12-17 15:48:10 +00:00
|
|
|
docs.SwaggerInfo.Version = config.Version
|
2024-12-17 16:28:37 +00:00
|
|
|
|
2024-12-14 08:40:45 +00:00
|
|
|
router.Get("/swagger/*", httpSwagger.WrapHandler)
|
|
|
|
|
2024-12-14 08:35:45 +00:00
|
|
|
router.Route("/tasks", func(taskRouter chi.Router) {
|
2024-12-15 06:16:51 +00:00
|
|
|
taskRouter.With(authGuard).Post("/", r.taskController.Create)
|
2024-12-14 08:35:45 +00:00
|
|
|
taskRouter.Route("/{taskID}", func(sTaskRouter chi.Router) {
|
2024-12-15 06:16:51 +00:00
|
|
|
sTaskRouter.With(authGuard).Post("/upload", r.taskController.Upload)
|
2024-12-14 08:35:45 +00:00
|
|
|
})
|
2024-12-12 13:27:07 +00:00
|
|
|
})
|
2024-12-04 11:46:42 +00:00
|
|
|
|
2024-12-12 13:27:07 +00:00
|
|
|
return router
|
2024-12-04 11:46:42 +00:00
|
|
|
}
|