ru.foodtechlab.lib.auth.service.domain.confirmationCodeSendingTask.usecases.CreateTaskUseCase Maven / Gradle / Ivy
package ru.foodtechlab.lib.auth.service.domain.confirmationCodeSendingTask.usecases;
import com.rcore.domain.commons.usecase.UseCase;
import com.rcore.domain.commons.usecase.model.SingleOutput;
import com.rcore.domain.commons.usecase.model.VoidInputValues;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import ru.foodtechlab.lib.auth.service.domain.confirmationCode.entity.ConfirmationCodeEntity;
import ru.foodtechlab.lib.auth.service.domain.confirmationCodeSendingTask.entity.ConfirmationCodeSendingTaskEntity;
import ru.foodtechlab.lib.auth.service.domain.confirmationCodeSendingTask.port.ConfirmationCodeSendingTaskIdGenerator;
import ru.foodtechlab.lib.auth.service.domain.confirmationCodeSendingTask.port.ConfirmationCodeSendingTaskRepository;
import ru.foodtechlab.lib.auth.service.domain.preference.entity.ConfirmationCodeMessageWebhookProviders;
import ru.foodtechlab.lib.auth.service.domain.preference.usecase.GetServicePreferenceUseCase;
@RequiredArgsConstructor
public class CreateTaskUseCase
extends UseCase> {
private final ConfirmationCodeSendingTaskRepository repository;
private final ConfirmationCodeSendingTaskIdGenerator> idGenerator;
private final GetServicePreferenceUseCase getSettings;
@Override
public SingleOutput execute(InputValues inputValues) {
var task = new ConfirmationCodeSendingTaskEntity();
task.setId(idGenerator.generate());
task.setConfirmationCode(inputValues.getConfirmationCode());
var settings = getSettings.execute(new VoidInputValues()).getValue();
var provider = settings.getWebhookProviderByType(inputValues.getConfirmationCode().getConfirmationCodeDestinationType());
task.setSendAttemptsLimit(provider
.map(ConfirmationCodeMessageWebhookProviders.Provider::getAttemptsLimit)
.orElse(null));
task.setWebhookProviderUrl(provider
.map(ConfirmationCodeMessageWebhookProviders.Provider::getUrl)
.orElse(null));
repository.save(task);
return SingleOutput.of(task);
}
@Value(staticConstructor = "of")
public static class InputValues implements UseCase.InputValues {
ConfirmationCodeEntity confirmationCode;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy