delete_chat_session_logic.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package chatsession
  2. import (
  3. "context"
  4. "fmt"
  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 DeleteChatSessionLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewDeleteChatSessionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteChatSessionLogic {
  18. return &DeleteChatSessionLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx}
  22. }
  23. func (l *DeleteChatSessionLogic) DeleteChatSession(req *types.IDsReq) (resp *types.BaseMsgResp, err error) {
  24. if len(req.Ids) == 0 {
  25. return nil, errorx.NewInvalidArgumentError("Ids参数不能为空")
  26. }
  27. rows, err := l.svcCtx.DB.ChatSession.Delete().Where(chatsession.IDIn(req.Ids...)).Exec(l.ctx)
  28. if err != nil {
  29. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  30. }
  31. msg := fmt.Sprintf("delete %d rows", rows)
  32. return &types.BaseMsgResp{
  33. Code: 0,
  34. Msg: msg,
  35. }, nil
  36. }