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
|
||||
}
|
||||
35
backend/modules/commands/tenant/expire.go
Normal file
35
backend/modules/commands/tenant/expire.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package tenant
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"backend/modules/users"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// @provider
|
||||
type Expire struct {
|
||||
userSvc *users.Service
|
||||
log *log.Entry `inject:"false"`
|
||||
}
|
||||
|
||||
// Prepare
|
||||
func (d *Expire) Prepare() error {
|
||||
d.log = log.WithField("module", "tenants.create")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Expire) RunE(slug string, expire time.Time) error {
|
||||
d.log.Infof("renew tenant %s expire at s %s", slug, expire)
|
||||
|
||||
err := d.userSvc.SetTenantExpireAtBySlug(context.Background(), slug, expire)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "renew tenant: %s expire at %s", slug, expire)
|
||||
}
|
||||
|
||||
d.log.Infof("renew tenant success: %s expire at %s", slug, expire)
|
||||
return nil
|
||||
}
|
||||
40
backend/modules/commands/tenant/provider.gen.go
Executable file
40
backend/modules/commands/tenant/provider.gen.go
Executable file
@@ -0,0 +1,40 @@
|
||||
package tenant
|
||||
|
||||
import (
|
||||
"backend/modules/users"
|
||||
|
||||
"git.ipao.vip/rogeecn/atom/container"
|
||||
"git.ipao.vip/rogeecn/atom/utils/opt"
|
||||
)
|
||||
|
||||
func Provide(opts ...opt.Option) error {
|
||||
if err := container.Container.Provide(func(
|
||||
userSvc *users.Service,
|
||||
) (*Create, error) {
|
||||
obj := &Create{
|
||||
userSvc: userSvc,
|
||||
}
|
||||
if err := obj.Prepare(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj, nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := container.Container.Provide(func(
|
||||
userSvc *users.Service,
|
||||
) (*Expire, error) {
|
||||
obj := &Expire{
|
||||
userSvc: userSvc,
|
||||
}
|
||||
if err := obj.Prepare(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj, nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user