package api import ( "net/http" "forge.cadoles.com/Cadoles/emissary/internal/datastore" "github.com/pkg/errors" "gitlab.com/wpetit/goweb/api" "gitlab.com/wpetit/goweb/logger" ) type CreateTenantRequest struct { Label string `json:"label" validate:"required"` } func (m *Mount) createTenant(w http.ResponseWriter, r *http.Request) { createTenantReq := &CreateTenantRequest{} if ok := api.Bind(w, r, createTenantReq); !ok { return } ctx := r.Context() tenant, err := m.tenantRepo.Create(ctx, createTenantReq.Label) if err != nil { err = errors.WithStack(err) logger.Error(ctx, "could not create tenant", logger.CapturedE(err)) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil) return } api.DataResponse(w, http.StatusOK, struct { Tenant *datastore.Tenant `json:"tenant"` }{ Tenant: tenant, }) }