Files
mp-qvyun/backend/modules/commands/tenant/bind.go
2024-12-12 19:26:48 +08:00

40 lines
858 B
Go

package tenant
import (
"context"
"backend/modules/users"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
// @provider
type Bind struct {
userSvc *users.Service
log *log.Entry `inject:"false"`
}
// Prepare
func (d *Bind) Prepare() error {
d.log = log.WithField("module", "tenants.bind")
return nil
}
func (d *Bind) RunE(slug string, userID int64) error {
d.log.Infof("bind tenant %s with user %d", slug, userID)
tenant, err := d.userSvc.GetTenantBySlug(context.Background(), slug)
if err != nil {
return errors.Wrapf(err, "get tenant: %s", slug)
}
err = d.userSvc.SetTenantBindUserID(context.Background(), tenant.ID, userID)
if err != nil {
return errors.Wrapf(err, "bind tenant: %s with user %d", tenant.ID, userID)
}
d.log.Infof("bind tenant success: %s(%d) with user %d", slug, tenant.ID, userID)
return nil
}