diff --git a/.gitignore b/.gitignore index 454729b..6950d24 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ obj bin appsettings.json -*.db \ No newline at end of file +*.db* \ No newline at end of file diff --git a/API/Controllers/ProductsController.cs b/API/Controllers/ProductsController.cs index 735d3e8..a3313eb 100644 --- a/API/Controllers/ProductsController.cs +++ b/API/Controllers/ProductsController.cs @@ -27,5 +27,18 @@ namespace API.Controllers { return await _repo.GetProductByIdAsync(id); } + + [HttpGet("brands")] + public async Task>> GetProductBrands() + { + return Ok(await _repo.GetProductBrandsAsync()); + } + + [HttpGet("types")] + public async Task>> GetProductTypes() + { + return Ok(await _repo.GetProductTypesAsync()); + + } } } \ No newline at end of file diff --git a/Core/Interfaces/iProductRepository.cs b/Core/Interfaces/iProductRepository.cs index 5e63b17..ce9b413 100644 --- a/Core/Interfaces/iProductRepository.cs +++ b/Core/Interfaces/iProductRepository.cs @@ -6,5 +6,7 @@ namespace Core.Interfaces { Task GetProductByIdAsync(int id); Task> GetProductsAync(); + Task> GetProductBrandsAsync(); + Task> GetProductTypesAsync(); } } \ No newline at end of file diff --git a/Infrastructure/Data/ProductRepository.cs b/Infrastructure/Data/ProductRepository.cs index cf7b2f1..88e70e1 100644 --- a/Infrastructure/Data/ProductRepository.cs +++ b/Infrastructure/Data/ProductRepository.cs @@ -12,14 +12,30 @@ namespace Infrastructure.Data _context = context; } + public async Task> GetProductBrandsAsync() + { + return await _context.ProductBrands.ToListAsync(); + } + public async Task GetProductByIdAsync(int id) { - return await _context.Products.FindAsync(id); + return await _context.Products + .Include(p => p.ProductType) + .Include(p => p.ProductBrand) + .FirstOrDefaultAsync(p => p.Id == id); } public async Task> GetProductsAync() { - return await _context.Products.ToListAsync(); + return await _context.Products + .Include(p => p.ProductType) + .Include(p => p.ProductBrand) + .ToListAsync(); + } + + public async Task> GetProductTypesAsync() + { + return await _context.ProductTypes.ToListAsync(); } } } \ No newline at end of file