feat(api): chi-роутер, check/apply хендлеры, changeset DTO
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/vasyakrg/dns-autoresolver/internal/diff"
|
||||
"github.com/vasyakrg/dns-autoresolver/internal/service"
|
||||
)
|
||||
|
||||
// CheckApplier is the service surface the API depends on.
|
||||
type CheckApplier interface {
|
||||
Check(ctx context.Context, domainID uuid.UUID) (diff.Changeset, error)
|
||||
Apply(ctx context.Context, domainID uuid.UUID, req service.ApplyRequest) (diff.Changeset, error)
|
||||
}
|
||||
|
||||
// API holds handler dependencies. Store/Cipher are used by CRUD handlers
|
||||
// (added by the implementer following the accounts pattern).
|
||||
type API struct {
|
||||
Svc CheckApplier
|
||||
}
|
||||
|
||||
func NewRouter(a *API) http.Handler {
|
||||
r := chi.NewRouter()
|
||||
r.Use(middleware.RequestID)
|
||||
r.Use(middleware.Recoverer)
|
||||
|
||||
r.Route("/api/v1/projects/{pid}", func(r chi.Router) {
|
||||
r.Route("/domains/{did}", func(r chi.Router) {
|
||||
r.Get("/check", a.handleCheck)
|
||||
r.Post("/apply", a.handleApply)
|
||||
})
|
||||
// accounts/templates/domains CRUD маунтятся тем же паттерном (Task 4 sqlc-методы)
|
||||
})
|
||||
return r
|
||||
}
|
||||
Reference in New Issue
Block a user