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

ru.foodtechlab.lib.auth.service.domain.roleAccess.usecase.CreateRoleAccessUseCase Maven / Gradle / Ivy

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

import com.rcore.domain.commons.usecase.UseCase;
import com.rcore.domain.commons.usecase.model.SingleOutput;
import com.rcore.domain.commons.validators.ValidationDomain;
import lombok.*;
import ru.foodtechlab.lib.auth.service.domain.Domain;
import ru.foodtechlab.lib.auth.service.domain.role.port.RoleRepository;
import ru.foodtechlab.lib.auth.service.domain.roleAccess.entity.RoleAccessEntity;
import ru.foodtechlab.lib.auth.service.domain.roleAccess.port.RoleAccessIdGenerator;
import ru.foodtechlab.lib.auth.service.domain.roleAccess.port.RoleAccessRepository;
import ru.foodtechlab.lib.auth.service.domain.roleAccess.validation.payload.MethodIsRequiredPayload;
import ru.foodtechlab.lib.auth.service.domain.roleAccess.validation.payload.RequestPathPatternIsRequiredPayload;
import ru.foodtechlab.lib.auth.service.domain.roleAccess.validation.payload.ServiceNameIsRequiredPayload;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

@RequiredArgsConstructor
public class CreateRoleAccessUseCase extends UseCase> {

    private final RoleAccessIdGenerator idGenerator;
    private final RoleAccessRepository repository;

    @Override
    public SingleOutput execute(InputValues inputValues) {

        var access = new RoleAccessEntity();
        access.setId(idGenerator.generate());
        access.setServiceName(inputValues.getServiceName());
        access.setMethod(inputValues.getMethod());
        access.setRequestPathPattern(inputValues.getRequestPathPattern());

        repository.save(access);

        return SingleOutput.of(access);
    }

    @ValidationDomain(domainName = Domain.ROLE_ACCESS)
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    @Data
    public static class InputValues implements UseCase.InputValues {
        @NotBlank
        private String serviceName;
        @NotNull
        private RoleAccessEntity.Method method;
        @NotBlank
        private String requestPathPattern;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy