in Source/Services/Tailwind.Traders.Product.Api/Controllers/ProductController.cs [116:149]
public async Task<IActionResult> FindProductsByTag(string tag)
{
var productTag = _productContext.Tags.SingleOrDefault(t => t.Value == tag);
if (productTag == null)
{
_logger.LogDebug("No tag found: " + tag);
return NoContent();
}
var items = await _productContext.ProductItems.Where(p => p.TagId == productTag.Id).Take(3).ToListAsync();
items.Join(
_productContext.ProductBrands,
_productContext.ProductTypes,
_productContext.ProductFeatures,
_productContext.Tags);
var data = items.Select(p => new ClassifiedProductDto()
{
Id = p.Id,
ImageUrl = $"{_settings.ProductImagesUrl}/{p.ImageName}",
Name = p.Name,
Price = p.Price
});
if (!data.Any())
{
_logger.LogDebug("No products found with the tag: " + tag);
return NoContent();
}
return Ok(data);
}