aides-repo-api/internal/router/router.go

51 lines
1.2 KiB
Go
Raw Normal View History

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"
"github.com/go-chi/chi/v5/middleware"
2024-12-04 11:46:42 +00:00
2024-12-12 20:36:38 +00:00
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/app"
2024-12-12 13:27:07 +00:00
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/controllers/taskcontroller"
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/middlewares"
2024-12-13 10:52:15 +00:00
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/reposervice"
2024-12-12 13:27:07 +00:00
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/taskservice"
2024-12-04 11:46:42 +00:00
)
type Router struct {
2024-12-12 20:36:38 +00:00
app *app.App
2024-12-04 11:46:42 +00:00
}
2024-12-12 20:36:38 +00:00
func New(app *app.App) *Router {
2024-12-12 13:27:07 +00:00
return &Router{
2024-12-12 20:36:38 +00:00
app: app,
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-04 11:46:42 +00:00
router := chi.NewRouter()
router.Use(middleware.Logger)
2024-12-12 13:27:07 +00:00
taskService := taskservice.New(
2024-12-12 20:36:38 +00:00
r.app,
2024-12-12 13:27:07 +00:00
)
2024-12-04 11:46:42 +00:00
2024-12-13 10:52:15 +00:00
repoService := reposervice.New(r.app)
repoService.ForceUpdate()
2024-12-12 13:27:07 +00:00
taskController := taskcontroller.New(
2024-12-12 20:36:38 +00:00
r.app,
2024-12-12 13:27:07 +00:00
taskService,
)
2024-12-04 11:46:42 +00:00
2024-12-12 20:36:38 +00:00
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)
})
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
}