guard/internal/logic/tokenservice/cancel_one_time_token_logic.go

47 lines
1.1 KiB
Go
Raw Normal View History

2024-08-10 01:52:23 +00:00
package tokenservicelogic
import (
2024-08-10 01:52:23 +00:00
ers "code.30cm.net/wanderland/library-go/errors"
"context"
"ark-permission/gen_result/pb/permission"
"ark-permission/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CancelOneTimeTokenLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCancelOneTimeTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelOneTimeTokenLogic {
return &CancelOneTimeTokenLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
2024-08-10 01:52:23 +00:00
type cancelOneTimeTokenReq struct {
Token []string `json:"token" validate:"required"`
}
// CancelOneTimeToken 取消一次性使用
2024-08-10 01:52:23 +00:00
func (l *CancelOneTimeTokenLogic) CancelOneTimeToken(in *permission.CancelOneTimeTokenReq) (*permission.OKResp, error) {
// 驗證所需
if err := l.svcCtx.Validate.ValidateAll(&cancelOneTimeTokenReq{
Token: in.GetToken(),
}); err != nil {
return nil, ers.InvalidFormat(err.Error())
}
err := l.svcCtx.TokenRedisRepo.DeleteOneTimeToken(l.ctx, in.GetToken(), nil)
if err != nil {
return nil, err
}
2024-08-10 01:52:23 +00:00
return &permission.OKResp{}, nil
}