Search in sources :

Example 1 with MultipleItemsResult

use of org.summerb.easycrud.rest.dto.MultipleItemsResult in project summerb by skarpushin.

the class EasyCrudRestControllerBase method getListWithQuery.

@PostMapping(path = "/query", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
public MultipleItemsResult<TId, TDto> getListWithQuery(@RequestBody EasyCrudQueryParams filteringParams, @RequestParam(value = "needPerms", required = false) boolean needPerms, @RequestParam(value = "referencesToResolve", required = false) List<String> referencesToResolve, @ApiIgnore PathVariablesMap pathVariables) throws Exception {
    if ((filteringParams.getOrderBy() == null || filteringParams.getOrderBy().length == 0) && defaultOrderBy != null) {
        filteringParams.setOrderBy(new OrderBy[] { defaultOrderBy });
    }
    if (filteringParams.getPagerParams() == null) {
        filteringParams.setPagerParams(defaultPagerParams);
    }
    Query query = filteringParamsToQueryConverter.convert(filteringParams.getFilterParams(), service.getDtoClass());
    query = queryNarrowerStrategy.narrow(query, pathVariables);
    PaginatedList<TDto> rows = service.query(filteringParams.getPagerParams(), query, filteringParams.getOrderBy());
    MultipleItemsResult<TId, TDto> ret = new MultipleItemsResult<>(service.getEntityTypeMessageCode(), rows);
    if (needPerms) {
        Preconditions.checkArgument(permissionsResolverStrategy != null, PERM_RESOLVER_REQ);
        permissionsResolverStrategy.resolvePermissions(ret, pathVariables);
    }
    if (rows.getHasItems() && !CollectionUtils.isEmpty(referencesToResolve)) {
        resolveReferences(referencesToResolve, ret, rows.getItems());
    }
    return convertBeforeReturnStrategy.convert(ret);
}
Also used : MultipleItemsResult(org.summerb.easycrud.rest.dto.MultipleItemsResult) Query(org.summerb.easycrud.api.query.Query) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

PostMapping (org.springframework.web.bind.annotation.PostMapping)1 Query (org.summerb.easycrud.api.query.Query)1 MultipleItemsResult (org.summerb.easycrud.rest.dto.MultipleItemsResult)1