using Core.Entities; using Microsoft.AspNetCore.Mvc; using Core.Interfaces; using Core.Specifications; namespace API.Controllers { [ApiController] [Route("api/[controller]")] public class ProductsController : ControllerBase { private readonly IGenericRepository _productsRepo; private readonly IGenericRepository _productBrandRepo; private readonly IGenericRepository _productTypeRepo; public ProductsController(IGenericRepository productsRepo, IGenericRepository productBrandRepo, IGenericRepository productTypeRepo) { _productTypeRepo = productTypeRepo; _productBrandRepo = productBrandRepo; _productsRepo = productsRepo; } [HttpGet] public async Task>> GetProducts() { var spec = new ProductsWithTypesAndBrandsSpecification(); var products = await _productsRepo.ListAsync(spec); return Ok(products); } [HttpGet("{id}")] public async Task> GetProduct(int id) { var spec = new ProductsWithTypesAndBrandsSpecification(id); return await _productsRepo.GetEntityWithSpec(spec); } [HttpGet("brands")] public async Task>> GetProductBrands() { return Ok(await _productBrandRepo.ListAllAsync()); } [HttpGet("types")] public async Task>> GetProductTypes() { return Ok(await _productTypeRepo.ListAllAsync()); } } }