public async Task <ActionResult <ProductToReturnDto> > GetProduct(int id) { var spec = new ProductsWithTypesAndPrandsSpecification(id); var product = await _productsRepo.GetEntityWithSpec(spec); if (product == null) { return(NotFound(new ApiResponse(404))); } return(_mapper.Map <Product, ProductToReturnDto>(product)); }
public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProducts( [FromQuery] ProductSpecParams productParams) { var spec = new ProductsWithTypesAndPrandsSpecification(productParams); var countSpec = new ProductWithFilterForCountSpecification(productParams); var totalItems = await _productsRepo.CountAsync(countSpec); var products = await _productsRepo.ListAsync(spec); var data = _mapper .Map <IReadOnlyList <Product>, IReadOnlyList <ProductToReturnDto> >(products); return(Ok(new Pagination <ProductToReturnDto>(productParams.PageIndex, productParams.PageSize, totalItems, data ))); }