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.
51 lines
1.1 KiB
51 lines
1.1 KiB
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
package ai
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"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 AiConversationDeleteLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 删除对话
|
|
func NewAiConversationDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AiConversationDeleteLogic {
|
|
return &AiConversationDeleteLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *AiConversationDeleteLogic) AiConversationDelete(req *types.AIConversationDeleteRequest) (resp *types.Response, err error) {
|
|
userId, _ := l.ctx.Value("userId").(int64)
|
|
if userId == 0 {
|
|
return nil, errors.New("unauthorized")
|
|
}
|
|
|
|
conv, err := model.AIConversationFindOne(l.ctx, l.svcCtx.DB, req.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if conv.UserId != userId {
|
|
return nil, errors.New("forbidden")
|
|
}
|
|
|
|
if err := model.AIConversationDelete(l.ctx, l.svcCtx.DB, req.Id); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &types.Response{Success: true}, nil
|
|
}
|
|
|