use of com.salesmanager.shop.model.entity.ListCriteria in project shopizer by shopizer-ecommerce.
the class ProductManufacturerApi method list.
@RequestMapping(value = "/manufacturers/", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ApiOperation(httpMethod = "GET", value = "List manufacturers by store", notes = "This request supports paging or not. Paging supports page number and request count", response = ReadableManufacturerList.class)
public ReadableManufacturerList list(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "page", required = false, defaultValue = "0") Integer page, @RequestParam(value = "count", required = false, defaultValue = "10") Integer count) {
ListCriteria listCriteria = new ListCriteria();
listCriteria.setName(name);
return manufacturerFacade.getAllManufacturers(merchantStore, language, listCriteria, page, count);
}
use of com.salesmanager.shop.model.entity.ListCriteria in project shopizer by shopizer-ecommerce.
the class ProductManufacturerApi method listByStore.
@RequestMapping(value = "/private/manufacturers/", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ApiOperation(httpMethod = "GET", value = "List manufacturers by store", notes = "This request supports paging or not. Paging supports page number and request count", response = ReadableManufacturerList.class)
public ReadableManufacturerList listByStore(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "page", required = false, defaultValue = "0") Integer page, @RequestParam(value = "count", required = false, defaultValue = "10") Integer count) {
ListCriteria listCriteria = new ListCriteria();
listCriteria.setName(name);
return manufacturerFacade.listByStore(merchantStore, language, listCriteria, page, count);
}
use of com.salesmanager.shop.model.entity.ListCriteria in project shopizer by shopizer-ecommerce.
the class CategoryApi method list.
/**
* Get all category starting from root filter can be used for filtering on
* fields only featured is supported
*
* @return
*/
@GetMapping(value = "/category", produces = { APPLICATION_JSON_VALUE })
@ApiOperation(httpMethod = "GET", value = "Get category hierarchy from root. Supports filtering FEATURED_CATEGORIES and VISIBLE ONLY by adding ?filter=[featured] or ?filter=[visible] or ? filter=[featured,visible", notes = "Does not return any product attached")
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") })
public ReadableCategoryList list(@RequestParam(value = "filter", required = false) List<String> filter, @RequestParam(value = "name", required = false) String name, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, @RequestParam(value = "page", required = false, defaultValue = "0") Integer page, @RequestParam(value = "count", required = false, defaultValue = "10") Integer count) {
ListCriteria criteria = new ListCriteria();
criteria.setName(name);
return categoryFacade.getCategoryHierarchy(merchantStore, criteria, DEFAULT_CATEGORY_DEPTH, language, filter, page, count);
}
use of com.salesmanager.shop.model.entity.ListCriteria in project shopizer by shopizer-ecommerce.
the class CategoryFacadeImpl method getCategoryHierarchy.
@Override
public ReadableCategoryList getCategoryHierarchy(MerchantStore store, ListCriteria criteria, int depth, Language language, List<String> filter, int page, int count) {
Validate.notNull(store, "MerchantStore can not be null");
// get parent store
try {
MerchantStore parent = merchantStoreService.getParent(store.getCode());
List<Category> categories = null;
ReadableCategoryList returnList = new ReadableCategoryList();
if (!CollectionUtils.isEmpty(filter) && filter.contains(FEATURED_CATEGORY)) {
categories = categoryService.getListByDepthFilterByFeatured(parent, depth, language);
returnList.setRecordsTotal(categories.size());
returnList.setNumber(categories.size());
returnList.setTotalPages(1);
} else {
org.springframework.data.domain.Page<Category> pageable = categoryService.getListByDepth(parent, language, criteria != null ? criteria.getName() : null, depth, page, count);
categories = pageable.getContent();
returnList.setRecordsTotal(pageable.getTotalElements());
returnList.setTotalPages(pageable.getTotalPages());
returnList.setNumber(categories.size());
}
List<ReadableCategory> readableCategories = null;
if (filter != null && filter.contains(VISIBLE_CATEGORY)) {
readableCategories = categories.stream().filter(Category::isVisible).map(cat -> categoryReadableCategoryConverter.convert(cat, store, language)).collect(Collectors.toList());
} else {
readableCategories = categories.stream().map(cat -> categoryReadableCategoryConverter.convert(cat, store, language)).collect(Collectors.toList());
}
Map<Long, ReadableCategory> readableCategoryMap = readableCategories.stream().collect(Collectors.toMap(ReadableCategory::getId, Function.identity()));
readableCategories.stream().filter(cat -> Objects.nonNull(cat.getParent())).filter(cat -> readableCategoryMap.containsKey(cat.getParent().getId())).forEach(readableCategory -> {
ReadableCategory parentCategory = readableCategoryMap.get(readableCategory.getParent().getId());
if (parentCategory != null) {
parentCategory.getChildren().add(readableCategory);
}
});
List<ReadableCategory> filteredList = readableCategoryMap.values().stream().collect(Collectors.toList());
// execute only if not admin filtered
if (filter == null || (filter != null && !filter.contains(ADMIN_CATEGORY))) {
filteredList = readableCategoryMap.values().stream().filter(cat -> cat.getDepth() == 0).sorted(Comparator.comparing(ReadableCategory::getSortOrder)).collect(Collectors.toList());
returnList.setNumber(filteredList.size());
}
returnList.setCategories(filteredList);
return returnList;
} catch (ServiceException e) {
throw new ServiceRuntimeException(e);
}
}
Aggregations