46 lines
1 KiB
Go
46 lines
1 KiB
Go
package router
|
|
|
|
import (
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/go-chi/chi/v5/middleware"
|
|
|
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/app"
|
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/controllers/taskcontroller"
|
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/middlewares"
|
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/taskservice"
|
|
)
|
|
|
|
type Router struct {
|
|
app *app.App
|
|
}
|
|
|
|
func New(app *app.App) *Router {
|
|
return &Router{
|
|
app: app,
|
|
}
|
|
}
|
|
|
|
func (r *Router) Setup() *chi.Mux {
|
|
router := chi.NewRouter()
|
|
router.Use(middleware.Logger)
|
|
|
|
taskService := taskservice.New(
|
|
r.app,
|
|
)
|
|
|
|
taskController := taskcontroller.New(
|
|
r.app,
|
|
taskService,
|
|
)
|
|
|
|
authGuard := middlewares.CreateAuthGuard(r.app.Config)
|
|
|
|
router.Route("/tasks", func(taskRouter chi.Router) {
|
|
taskRouter.With(authGuard).Post("/", taskController.Create)
|
|
taskRouter.Route("/{taskID}", func(sTaskRouter chi.Router) {
|
|
sTaskRouter.With(authGuard).Post("/upload", taskController.Upload)
|
|
})
|
|
})
|
|
|
|
return router
|
|
}
|