Skip to content

Instantly share code, notes, and snippets.

@merken
Created December 29, 2019 11:55
Show Gist options
  • Save merken/a813a8243d3de6c1e0ef1d2a5dc6eee1 to your computer and use it in GitHub Desktop.
Save merken/a813a8243d3de6c1e0ef1d2a5dc6eee1 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Contract;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace Products.API.Controllers
{
[ApiController]
[Route("[controller]")]
public class ProductsController : ControllerBase
{
private readonly ILogger<ProductsController> logger;
private readonly IProductsRepository productsRepository;
public ProductsController(ILogger<ProductsController> logger, IProductsRepository productsRepository)
{
this.logger = logger;
this.productsRepository = productsRepository;
}
[HttpGet]
public Task<IEnumerable<Product>> Get()
{
return this.productsRepository.All();
}
[HttpGet("{id}")]
public Task<Product> Get(string id)
{
return this.productsRepository.Get(int.Parse(id));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment