Sky.Net/API/Controllers/ProductsController.cs

31 lines
751 B
C#
Raw Normal View History

2022-05-09 14:41:15 -07:00
using Core.Entities;
using Microsoft.AspNetCore.Mvc;
2022-05-09 17:07:59 -07:00
using Core.Interfaces;
2022-05-09 14:41:15 -07:00
namespace API.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
2022-05-09 17:07:59 -07:00
private readonly iProductRepository _repo;
public ProductsController(iProductRepository repo)
2022-05-09 14:41:15 -07:00
{
2022-05-09 17:07:59 -07:00
_repo = repo;
2022-05-09 14:41:15 -07:00
}
[HttpGet]
public async Task<ActionResult<List<Product>>> GetProducts()
{
2022-05-09 17:07:59 -07:00
var products = await _repo.GetProductsAync();
2022-05-09 14:41:15 -07:00
return Ok(products);
}
[HttpGet("{id}")]
public async Task<ActionResult<Product>> GetProduct(int id)
{
2022-05-09 17:07:59 -07:00
return await _repo.GetProductByIdAsync(id);
2022-05-09 14:41:15 -07:00
}
}
}