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.
48 lines
1.2 KiB
48 lines
1.2 KiB
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"healthapi/internal/model"
|
|
"healthapi/internal/svc"
|
|
"healthapi/internal/types"
|
|
"healthapi/pkg/errorx"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type DeleteConversationLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewDeleteConversationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteConversationLogic {
|
|
return &DeleteConversationLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *DeleteConversationLogic) DeleteConversation(req *types.ConversationIdReq) (resp *types.CommonResp, err error) {
|
|
userID, err := GetUserIDFromCtx(l.ctx)
|
|
if err != nil {
|
|
return nil, errorx.ErrUnauthorized
|
|
}
|
|
|
|
var conversation model.Conversation
|
|
if err := l.svcCtx.DB.Where("id = ? AND user_id = ?", req.Id, userID).First(&conversation).Error; err != nil {
|
|
return nil, errorx.ErrNotFound
|
|
}
|
|
|
|
// 删除消息
|
|
l.svcCtx.DB.Where("conversation_id = ?", conversation.ID).Delete(&model.Message{})
|
|
|
|
// 删除对话
|
|
if err := l.svcCtx.DB.Delete(&conversation).Error; err != nil {
|
|
return nil, errorx.ErrServerError
|
|
}
|
|
|
|
return &types.CommonResp{Code: 0, Message: "删除成功"}, nil
|
|
}
|
|
|