Created
February 4, 2019 22:42
-
-
Save evgomes/b41037451582792315634540584be0df to your computer and use it in GitHub Desktop.
ProductsController from Sueprmarket API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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