update_chat_session_logic.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 UpdateChatSessionLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewUpdateChatSessionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateChatSessionLogic {
  18. return &UpdateChatSessionLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx}
  22. }
  23. func (l *UpdateChatSessionLogic) UpdateChatSession(req *types.ChatSessionInfo) (*types.BaseMsgResp, error) {
  24. var id uint64
  25. var name string
  26. if req.Id != nil && *req.Id > 0 {
  27. id = *req.Id
  28. }
  29. if req.Name != nil && *req.Name != "" {
  30. name = *req.Name
  31. }
  32. if id == 0 || name == "" {
  33. return nil, errorx.NewInvalidArgumentError("参数错误")
  34. }
  35. _, err := l.svcCtx.DB.ChatSession.Update().Where(chatsession.ID(id)).SetName(name).Save(l.ctx)
  36. if err != nil {
  37. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  38. }
  39. return &types.BaseMsgResp{
  40. Code: 0,
  41. Msg: errormsg.Success,
  42. }, nil
  43. }