31 lines
751 B
C#
31 lines
751 B
C#
using Core.Entities;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Core.Interfaces;
|
|
|
|
namespace API.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class ProductsController : ControllerBase
|
|
{
|
|
private readonly iProductRepository _repo;
|
|
public ProductsController(iProductRepository repo)
|
|
{
|
|
_repo = repo;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<ActionResult<List<Product>>> GetProducts()
|
|
{
|
|
var products = await _repo.GetProductsAync();
|
|
|
|
return Ok(products);
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
public async Task<ActionResult<Product>> GetProduct(int id)
|
|
{
|
|
return await _repo.GetProductByIdAsync(id);
|
|
}
|
|
}
|
|
} |