Subversion Repositories SmartDukaan

Rev

Rev 31536 | Rev 33122 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.service.catalog;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.spice.profitmandi.dao.entity.catalog.BrandCatalog;
import com.spice.profitmandi.dao.entity.catalog.BrandCategory;
import com.spice.profitmandi.dao.repository.catalog.BrandCategoryRepository;
import com.spice.profitmandi.dao.repository.catalog.BrandsRepository;
import com.spice.profitmandi.dao.repository.dtr.RetailerBlockBrandsRepository;

@Component
public class BrandsServiceImpl implements BrandsService {

        @Autowired
        private BrandCategoryRepository brandCategoryRepository;

        @Autowired
        private BrandsRepository brandCatalogRepository;

        @Autowired
        private RetailerBlockBrandsRepository retailerBlockBrandsRepository;

        @Override
        public List<BrandCatalog> getBrands(int categoryId) {
                List<BrandCategory> brandCategories = brandCategoryRepository.selectByCategoryId(categoryId);
                List<Integer> brandIds = brandCategories.stream().map(x->x.getBrandId()).collect(Collectors.toList());
                List<BrandCatalog> brandCatalogList = brandCatalogRepository.selectByIds(brandIds);
                return brandCatalogList;
        }

        @Override
        public List<BrandCatalog> getBrandsToDisplay(int categoryId) {
                List<BrandCategory> brandCategories = brandCategoryRepository.selectByCategoryId(categoryId).stream()
                                .filter(x -> x.isActive()).collect(Collectors.toList());

                Map<Integer, BrandCategory> brandCategoryMap = brandCategories.stream()
                                .collect(Collectors.toMap(x -> x.getBrandId(), x -> x));

                List<Integer> brandIds = brandCategories.stream().map(x -> x.getBrandId()).collect(Collectors.toList());

                List<BrandCatalog> brands = brandCatalogRepository.selectByIds(brandIds);

                for (BrandCatalog brand : brands) {
                        brand.setBrandCategory(brandCategoryMap.get(brand.getId()));
                }
                return brands;
        }

}