ru.foodtechlab.lib.auth.service.domain.token.usecases.ExpireRefreshTokenByTimeUseCase Maven / Gradle / Ivy
package ru.foodtechlab.lib.auth.service.domain.token.usecases;
import com.rcore.domain.commons.usecase.UseCase;
import com.rcore.domain.commons.usecase.model.IdInputValues;
import com.rcore.domain.commons.usecase.model.SingletonEntityOutputValues;
import lombok.RequiredArgsConstructor;
import ru.foodtechlab.lib.auth.service.domain.token.entity.RefreshTokenEntity;
import ru.foodtechlab.lib.auth.service.domain.token.exception.RefreshTokenNotFoundException;
import ru.foodtechlab.lib.auth.service.domain.token.port.RefreshTokenRepository;
import java.time.Instant;
@RequiredArgsConstructor
public class ExpireRefreshTokenByTimeUseCase extends UseCase, SingletonEntityOutputValues> {
private final RefreshTokenRepository refreshTokenRepository;
private final DeactivateAccessTokensByRefreshToken deactivateAccessTokensByRefreshToken;
@Override
public SingletonEntityOutputValues execute(IdInputValues inputValues) {
RefreshTokenEntity refreshTokenEntity = refreshTokenRepository.findById(inputValues.getId())
.orElseThrow(() -> new RefreshTokenNotFoundException(inputValues.getId()));
refreshTokenEntity.setExpireAt(Instant.now());
deactivateAccessTokensByRefreshToken.execute(DeactivateAccessTokensByRefreshToken.InputValues.of(refreshTokenEntity));
return SingletonEntityOutputValues.of(refreshTokenRepository.save(refreshTokenEntity));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy