init: taotie-api 项目初始化
This commit is contained in:
45
service/tenantservice.go
Normal file
45
service/tenantservice.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"taotie-api/common"
|
||||
"taotie-api/core"
|
||||
"taotie-api/model/do/tenantdo"
|
||||
"taotie-api/model/po"
|
||||
"taotie-api/repo"
|
||||
|
||||
"github.com/gookit/goutil/errorx"
|
||||
)
|
||||
|
||||
type TenantService struct {
|
||||
cfg *core.Configuration
|
||||
tenantRepo *repo.TenantRepo[*po.TTenant]
|
||||
}
|
||||
|
||||
func NewTenantService(cfg *core.Configuration, tenantRepo *repo.TenantRepo[*po.TTenant]) *TenantService {
|
||||
return &TenantService{cfg, tenantRepo}
|
||||
}
|
||||
|
||||
func (rp *TenantService) Create(ctx context.Context, in *tenantdo.CreateIn) (*tenantdo.CreateOut, error) {
|
||||
// 查重
|
||||
tenant, err := rp.tenantRepo.FindOneByTenantName(ctx, in.TenantName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tenant != nil {
|
||||
return nil, errorx.With(common.ErrSysDuplicate, "租户名称重复")
|
||||
}
|
||||
|
||||
// 创建租户
|
||||
tenant = &po.TTenant{
|
||||
TenantName: in.TenantName,
|
||||
}
|
||||
tenantId, err := rp.tenantRepo.Create(ctx, tenant)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &tenantdo.CreateOut{
|
||||
Id: tenantId,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user