get_chat_session_by_id_logic.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package chatsession
  2. import (
  3. "context"
  4. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  5. "github.com/zeromicro/go-zero/core/errorx"
  6. "wechat-api/ent/chatsession"
  7. "wechat-api/internal/utils/dberrorhandler"
  8. "wechat-api/internal/svc"
  9. "wechat-api/internal/types"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type GetChatSessionByIdLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewGetChatSessionByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetChatSessionByIdLogic {
  18. return &GetChatSessionByIdLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx}
  22. }
  23. func (l *GetChatSessionByIdLogic) GetChatSessionById(req *types.IDReq) (resp *types.ChatSessionInfoResp, err error) {
  24. if req.Id == 0 {
  25. return nil, errorx.NewDefaultError("参数错误")
  26. }
  27. data, err := l.svcCtx.DB.ChatSession.Query().Where(chatsession.ID(req.Id)).Only(l.ctx)
  28. if err != nil {
  29. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  30. }
  31. return &types.ChatSessionInfoResp{
  32. BaseDataInfo: types.BaseDataInfo{
  33. Code: 0,
  34. Msg: errormsg.Success,
  35. },
  36. Data: types.ChatSessionInfo{
  37. Name: &data.Name,
  38. UserId: &data.UserID,
  39. BotId: &data.BotID,
  40. BotType: &data.BotType,
  41. },
  42. }, nil
  43. }