feat: done
This commit is contained in:
@@ -2,6 +2,7 @@ package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"quyun/v2/app/http/super/dto"
|
||||
@@ -183,6 +184,31 @@ func (t *tenant) FindByID(ctx context.Context, id int64) (*models.Tenant, error)
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (t *tenant) FindByCode(ctx context.Context, code string) (*models.Tenant, error) {
|
||||
code = strings.TrimSpace(code)
|
||||
if code == "" {
|
||||
return nil, errors.New("tenant code is empty")
|
||||
}
|
||||
code = strings.ToLower(code)
|
||||
|
||||
var m models.Tenant
|
||||
err := models.Q.Tenant.WithContext(ctx).UnderlyingDB().Where("lower(code) = ?", code).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "find by code failed, code: %s", code)
|
||||
}
|
||||
return &m, nil
|
||||
}
|
||||
|
||||
func (t *tenant) FindTenantUser(ctx context.Context, tenantID, userID int64) (*models.TenantUser, error) {
|
||||
logrus.WithField("tenant_id", tenantID).WithField("user_id", userID).Info("find tenant user")
|
||||
tbl, query := models.TenantUserQuery.QueryContext(ctx)
|
||||
m, err := query.Where(tbl.TenantID.Eq(tenantID), tbl.UserID.Eq(userID)).First()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "find tenant user failed, tenantID: %d, userID: %d", tenantID, userID)
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddExpireDuration
|
||||
func (t *tenant) AddExpireDuration(ctx context.Context, tenantID int64, duration time.Duration) error {
|
||||
logrus.WithField("tenant_id", tenantID).WithField("duration", duration).Info("add expire duration")
|
||||
|
||||
Reference in New Issue
Block a user