healthapp
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.
 
 
 
 
 
 

54 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 CreateConversationLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCreateConversationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateConversationLogic {
return &CreateConversationLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CreateConversationLogic) CreateConversation(req *types.CreateConversationReq) (resp *types.ConversationItem, err error) {
userID, err := GetUserIDFromCtx(l.ctx)
if err != nil {
return nil, errorx.ErrUnauthorized
}
title := req.Title
if title == "" {
title = "新对话"
}
conversation := model.Conversation{
UserID: userID,
Title: title,
}
if err := l.svcCtx.DB.Create(&conversation).Error; err != nil {
return nil, errorx.ErrServerError
}
return &types.ConversationItem{
ID: uint(conversation.ID),
Title: conversation.Title,
CreatedAt: conversation.CreatedAt.Format("2006-01-02 15:04:05"),
UpdatedAt: conversation.UpdatedAt.Format("2006-01-02 15:04:05"),
}, nil
}