This commit is contained in:
2026-08-15 01:40:51 +08:00
parent 2f165d3a45
commit e55fb57432
29 changed files with 163 additions and 124 deletions
+9 -3
View File
@@ -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)
}