create_chat_session_logic.go 1004 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package chatsession
  2. import (
  3. "context"
  4. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  5. "wechat-api/internal/utils/dberrorhandler"
  6. "wechat-api/internal/svc"
  7. "wechat-api/internal/types"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type CreateChatSessionLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewCreateChatSessionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateChatSessionLogic {
  16. return &CreateChatSessionLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx}
  20. }
  21. func (l *CreateChatSessionLogic) CreateChatSession(req *types.ChatSessionInfo) (*types.BaseMsgResp, error) {
  22. err := l.svcCtx.DB.ChatSession.Create().
  23. SetNotNilName(req.Name).
  24. SetNotNilUserID(req.UserId).
  25. SetNotNilBotID(req.BotId).
  26. SetNotNilBotType(req.BotType).
  27. Exec(l.ctx)
  28. if err != nil {
  29. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  30. }
  31. return &types.BaseMsgResp{
  32. Code: 0,
  33. Msg: errormsg.Success,
  34. }, nil
  35. }