Skip to content

Commit

Permalink
Consistent naming for http handler
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkRunWu committed Dec 15, 2023
1 parent 3c263ea commit d3dcd31
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
8 changes: 1 addition & 7 deletions internal/handler/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
Expand Down
8 changes: 4 additions & 4 deletions internal/handler/controller/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit d3dcd31

Please sign in to comment.