feat(api): chi-роутер, check/apply хендлеры, changeset DTO

This commit is contained in:
2026-07-03 14:28:06 +07:00
parent 8a2d985197
commit fdf90a7c23
6 changed files with 243 additions and 0 deletions
+40
View File
@@ -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
}