From d3dcd31d0085bb3507500e9b4b9d2f00a240153c Mon Sep 17 00:00:00 2001 From: mark wu Date: Fri, 15 Dec 2023 17:16:02 +0800 Subject: [PATCH] Consistent naming for http handler --- internal/handler/controller/controller.go | 8 +------- internal/handler/controller/domain.go | 8 ++++---- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/internal/handler/controller/controller.go b/internal/handler/controller/controller.go index 594a792..4eeb852 100644 --- a/internal/handler/controller/controller.go +++ b/internal/handler/controller/controller.go @@ -93,13 +93,7 @@ func (c *Controller) Handler() http.Handler { r.Get("/", c.handleDomainList) r.With(c.requireAccessAdmin()).Route("/{domain-name}", func(r chi.Router) { - r.With(c.requireAccessDeployer()).Post("/", func(w http.ResponseWriter, r *http.Request) { - if c.Config.DomainVerificationEnabled { - c.handleDomainVerification(w, r) - } else { - c.handleDomainCreate(w, r) - } - }) + r.With(c.requireAccessDeployer()).Post("/", c.handleDomainCreate) r.With(c.requireAccessDeployer()).Delete("/", c.handleDomainDelete) }) }) diff --git a/internal/handler/controller/domain.go b/internal/handler/controller/domain.go index b706799..b462a76 100644 --- a/internal/handler/controller/domain.go +++ b/internal/handler/controller/domain.go @@ -49,7 +49,7 @@ func (c *Controller) handleDomainList(w http.ResponseWriter, r *http.Request) { }) } -func (c *Controller) handleDomainVerification(w http.ResponseWriter, r *http.Request) { +func (c *Controller) handleDomainCreate(w http.ResponseWriter, r *http.Request) { app := get[*models.App](r) domainName := chi.URLParam(r, "domain-name") @@ -59,8 +59,8 @@ func (c *Controller) handleDomainVerification(w http.ResponseWriter, r *http.Req } domain, _ := c.DB.GetDomainByName(r.Context(), domainName) - if domain != nil { - c.handleDomainCreate(w, r) + if domain != nil || !c.Config.DomainVerificationEnabled { + c.createDomain(w, r) return } respond(w, withTx(r.Context(), c.DB, func(tx db.Tx) (any, error) { @@ -89,7 +89,7 @@ func (c *Controller) handleDomainVerification(w http.ResponseWriter, r *http.Req })) } -func (c *Controller) handleDomainCreate(w http.ResponseWriter, r *http.Request) { +func (c *Controller) createDomain(w http.ResponseWriter, r *http.Request) { app := get[*models.App](r) domainName := chi.URLParam(r, "domain-name")