Added Brand and Types to Controller
This commit is contained in:
parent
f185ef9163
commit
7601a394b4
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
|||||||
obj
|
obj
|
||||||
bin
|
bin
|
||||||
appsettings.json
|
appsettings.json
|
||||||
*.db
|
*.db*
|
@ -27,5 +27,18 @@ namespace API.Controllers
|
|||||||
{
|
{
|
||||||
return await _repo.GetProductByIdAsync(id);
|
return await _repo.GetProductByIdAsync(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("brands")]
|
||||||
|
public async Task<ActionResult<IReadOnlyList<ProductBrand>>> GetProductBrands()
|
||||||
|
{
|
||||||
|
return Ok(await _repo.GetProductBrandsAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("types")]
|
||||||
|
public async Task<ActionResult<IReadOnlyList<ProductType>>> GetProductTypes()
|
||||||
|
{
|
||||||
|
return Ok(await _repo.GetProductTypesAsync());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,5 +6,7 @@ namespace Core.Interfaces
|
|||||||
{
|
{
|
||||||
Task<Product> GetProductByIdAsync(int id);
|
Task<Product> GetProductByIdAsync(int id);
|
||||||
Task<IReadOnlyList<Product>> GetProductsAync();
|
Task<IReadOnlyList<Product>> GetProductsAync();
|
||||||
|
Task<IReadOnlyList<ProductBrand>> GetProductBrandsAsync();
|
||||||
|
Task<IReadOnlyList<ProductType>> GetProductTypesAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,14 +12,30 @@ namespace Infrastructure.Data
|
|||||||
_context = context;
|
_context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IReadOnlyList<ProductBrand>> GetProductBrandsAsync()
|
||||||
|
{
|
||||||
|
return await _context.ProductBrands.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<Product> GetProductByIdAsync(int id)
|
public async Task<Product> 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<IReadOnlyList<Product>> GetProductsAync()
|
public async Task<IReadOnlyList<Product>> GetProductsAync()
|
||||||
{
|
{
|
||||||
return await _context.Products.ToListAsync();
|
return await _context.Products
|
||||||
|
.Include(p => p.ProductType)
|
||||||
|
.Include(p => p.ProductBrand)
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IReadOnlyList<ProductType>> GetProductTypesAsync()
|
||||||
|
{
|
||||||
|
return await _context.ProductTypes.ToListAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user