Skip to content

Instantly share code, notes, and snippets.

@evgomes
Created February 4, 2019 22:42
Show Gist options
  • Save evgomes/b41037451582792315634540584be0df to your computer and use it in GitHub Desktop.
Save evgomes/b41037451582792315634540584be0df to your computer and use it in GitHub Desktop.
ProductsController from Sueprmarket API
using System.Collections.Generic;
using System.Threading.Tasks;
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Supermarket.API.Domain.Models;
using Supermarket.API.Domain.Services;
using Supermarket.API.Resources;
namespace Supermarket.API.Controllers
{
[Route("/api/[controller]")]
public class ProductsController : Controller
{
private readonly IProductService _productService;
private readonly IMapper _mapper;
public ProductsController(IProductService productService, IMapper mapper)
{
_productService = productService;
_mapper = mapper;
}
[HttpGet]
public async Task<IEnumerable<ProductResource>> ListAsync()
{
var products = await _productService.ListAsync();
var resources = _mapper.Map<IEnumerable<Product>, IEnumerable<ProductResource>>(products);
return resources;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment