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

com.alon.spring.crud.api.controller.input.SearchResolver Maven / Gradle / Ivy

Go to download

Fornece implementação básica e expansível para criação API's CRUD com Spring Boot e Spring Data JPA.

There is a newer version: 1.0.9
Show newest version
package com.alon.spring.crud.api.controller.input;

import com.alon.spring.crud.core.properties.Properties;
import com.alon.spring.specification.ExpressionSpecification;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ResponseStatusException;

@Component
public class SearchResolver {

    private Properties properties;

    public SearchResolver(Properties properties) {
        this.properties = properties;
    }

    public  Specification resolve(SEARCH_INPUT_TYPE search) {
        if (search.filterPresent()) {
            if (!properties.search.enableExpressionFilter)
                throw new ResponseStatusException(HttpStatus.LOCKED,
                        "The filter by expression feature is not enabled.");

            return ExpressionSpecification.of(search.getFilter());
        }

        return search.toSpecification();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy