You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
46 lines
1.1 KiB
package ai
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/youruser/base/internal/svc"
|
|
"github.com/youruser/base/internal/types"
|
|
"github.com/youruser/base/model"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type AiSystemKeyDeleteLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewAiSystemKeyDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AiSystemKeyDeleteLogic {
|
|
return &AiSystemKeyDeleteLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *AiSystemKeyDeleteLogic) AiSystemKeyDelete(req *types.AIApiKeyDeleteRequest) (resp *types.Response, err error) {
|
|
existing, err := model.AIApiKeyFindOne(l.ctx, l.svcCtx.DB, req.Id)
|
|
if err != nil {
|
|
if err == model.ErrNotFound {
|
|
return nil, fmt.Errorf("系统密钥不存在")
|
|
}
|
|
return nil, fmt.Errorf("查询系统密钥失败: %v", err)
|
|
}
|
|
|
|
if existing.UserId != 0 {
|
|
return nil, fmt.Errorf("该密钥不是系统密钥")
|
|
}
|
|
|
|
if err = model.AIApiKeyDelete(l.ctx, l.svcCtx.DB, req.Id); err != nil {
|
|
return nil, fmt.Errorf("删除系统密钥失败: %v", err)
|
|
}
|
|
|
|
return &types.Response{Code: 0, Message: "ok", Success: true}, nil
|
|
}
|
|
|