feat: add tenant commands
This commit is contained in:
34
backend/modules/commands/tenant/create.go
Normal file
34
backend/modules/commands/tenant/create.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package tenant
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"backend/modules/users"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// @provider
|
||||
type Create struct {
|
||||
userSvc *users.Service
|
||||
log *log.Entry `inject:"false"`
|
||||
}
|
||||
|
||||
// Prepare
|
||||
func (d *Create) Prepare() error {
|
||||
d.log = log.WithField("module", "tenants.create")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Create) RunE(name, slug string) error {
|
||||
d.log.Infof("create tenant %s(%s)", name, slug)
|
||||
|
||||
err := d.userSvc.CreateTenant(context.Background(), name, slug)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "create tenant: %s(%s)", name, slug)
|
||||
}
|
||||
|
||||
d.log.Infof("create tenant success: %s(%s)", name, slug)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user