All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.foodtechlab.lib.auth.service.domain.credential.usecases.FindCredentialsByRoleUseCase Maven / Gradle / Ivy

There is a newer version: 4.1.0
Show newest version
package ru.foodtechlab.lib.auth.service.domain.credential.usecases;

import com.rcore.domain.commons.usecase.UseCase;
import com.rcore.domain.commons.usecase.model.FiltersInputValues;
import com.rcore.domain.commons.usecase.model.SearchResultEntityOutputValues;
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.exceptions.RoleEmptyException;
import ru.foodtechlab.lib.auth.service.domain.credential.filters.SearchByRoleFilters;
import ru.foodtechlab.lib.auth.service.domain.credential.port.CredentialRepository;

import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;

@RequiredArgsConstructor
public class FindCredentialsByRoleUseCase extends UseCase, SearchResultEntityOutputValues> {

    private final CredentialRepository credentialRepository;

    @Override
    public SearchResultEntityOutputValues execute(FiltersInputValues inputValues) {
        validate(inputValues);
        return SearchResultEntityOutputValues.of(credentialRepository.findByRole(inputValues.getFilters()));
    }

    @ValidationDomain(domainName = Domain.CREDENTIAL)
    @Value(staticConstructor = "of")
    public static class InputValues implements UseCase.InputValues {
        @NotBlank
        List roles = new ArrayList<>();
    }

    private void validate(FiltersInputValues inputValues) {
        if (inputValues.getFilters().getRoles() == null || inputValues.getFilters().getRoles().size() == 0)
            throw new RoleEmptyException();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy