ru.foodtechlab.lib.auth.service.domain.credential.usecases.FindCredentialByUsernameUseCase Maven / Gradle / Ivy
package ru.foodtechlab.lib.auth.service.domain.credential.usecases;
import com.rcore.commons.utils.StringUtils;
import com.rcore.domain.commons.usecase.UseCase;
import com.rcore.domain.commons.usecase.model.SingleOutput;
import com.rcore.domain.commons.validators.ValidationDomain;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import ru.foodtechlab.lib.auth.service.domain.Domain;
import ru.foodtechlab.lib.auth.service.domain.credential.entity.CredentialEntity;
import ru.foodtechlab.lib.auth.service.domain.credential.port.CredentialRepository;
import ru.foodtechlab.lib.auth.service.domain.credential.validation.payload.InvalidUsernamePayload;
import javax.validation.constraints.NotBlank;
import java.util.Optional;
@RequiredArgsConstructor
public class FindCredentialByUsernameUseCase extends UseCase>> {
private final CredentialRepository credentialRepository;
@Override
public SingleOutput> execute(InputValues inputValues) {
if (inputValues.getUsername() == null || !StringUtils.hasText(inputValues.getUsername()))
return SingleOutput.of(Optional.empty());
return SingleOutput.of(credentialRepository.findByUsername(inputValues.getUsername()));
}
@ValidationDomain(domainName = Domain.CREDENTIAL)
@Value(staticConstructor = "of")
public static class InputValues implements UseCase.InputValues {
String username;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy