优化
This commit is contained in:
@@ -29,7 +29,13 @@ type APITokenRepo interface {
|
||||
IsTokenDisabled(context.Context, string) (bool, error)
|
||||
}
|
||||
|
||||
func (uc *SettingsUsecase) PrepareAPIToken(ctx context.Context, userID, authorityID uint, days int) (*User, time.Duration, error) {
|
||||
type TokenUsecase struct{ APITokenRepo }
|
||||
|
||||
func NewTokenUsecase(repo APITokenRepo) *TokenUsecase {
|
||||
return &TokenUsecase{APITokenRepo: repo}
|
||||
}
|
||||
|
||||
func (uc *TokenUsecase) PrepareAPIToken(ctx context.Context, userID, authorityID uint, days int) (*User, time.Duration, error) {
|
||||
user, allowed, err := uc.UserHasAuthority(ctx, userID, authorityID)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
@@ -44,6 +50,6 @@ func (uc *SettingsUsecase) PrepareAPIToken(ctx context.Context, userID, authorit
|
||||
return user, duration, nil
|
||||
}
|
||||
|
||||
func (uc *SettingsUsecase) DisableToken(ctx context.Context, id uint) error {
|
||||
return uc.SettingsRepo.DisableAndBlacklistAPIToken(ctx, id)
|
||||
func (uc *TokenUsecase) DisableToken(ctx context.Context, id uint) error {
|
||||
return uc.APITokenRepo.DisableAndBlacklistAPIToken(ctx, id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user