clear_token_by_id_logic.go 1001 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package token
  2. import (
  3. "context"
  4. "github.com/zeromicro/go-zero/core/errorx"
  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 ClearTokenByIdLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewClearTokenByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClearTokenByIdLogic {
  16. return &ClearTokenByIdLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx}
  20. }
  21. func (l *ClearTokenByIdLogic) ClearTokenById(req *types.IDReq) (*types.BaseMsgResp, error) {
  22. isAdmin := l.ctx.Value("isAdmin").(bool)
  23. resp := types.BaseMsgResp{
  24. Code: 0,
  25. Msg: "操作成功",
  26. }
  27. if isAdmin {
  28. _, err := l.svcCtx.DB.Token.UpdateOneID(req.Id).SetMAC("").Save(l.ctx)
  29. if err != nil {
  30. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  31. }
  32. } else {
  33. return nil, errorx.NewInvalidArgumentError("暂无权限")
  34. }
  35. return &resp, nil
  36. }