delete_api_session_logic.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package chatsession
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  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 DeleteApiSessionLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewDeleteApiSessionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteApiSessionLogic {
  18. return &DeleteApiSessionLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx}
  22. }
  23. func (l *DeleteApiSessionLogic) DeleteApiSession(req *types.IDsReq) (*types.BaseMsgResp, error) {
  24. userId := l.ctx.Value("userId").(uint64)
  25. msg := errormsg.Success
  26. ids := req.Ids
  27. if len(ids) > 0 {
  28. num, err := l.svcCtx.DB.ChatSession.Delete().Where(chatsession.UserID(userId), chatsession.IDIn(ids...)).Exec(l.ctx)
  29. if err != nil {
  30. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  31. }
  32. msg = fmt.Sprintf("delete %d rows", num)
  33. }
  34. return &types.BaseMsgResp{
  35. Code: 0,
  36. Msg: msg,
  37. }, nil
  38. }