Feature/migrate to minimal api (#662)
* migrate from classic controller to minimal api * fix all PublicApi integration test * update all nuget package add forget project * fix pay now * Adapt readme use in memory database * undo AuthenticateEndpoint to use EndpointBaseAsync * Update README.md Co-authored-by: Steve Smith <steve@kentsmiths.com> Co-authored-by: Steve Smith <steve@kentsmiths.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
||||
using MinimalApi.Endpoint;
|
||||
|
||||
namespace Microsoft.eShopWeb.PublicApi.CatalogBrandEndpoints;
|
||||
|
||||
/// <summary>
|
||||
/// List Catalog Brands
|
||||
/// </summary>
|
||||
public class CatalogBrandListEndpoint : IEndpoint<IResult>
|
||||
{
|
||||
private IRepository<CatalogBrand> _catalogBrandRepository;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public CatalogBrandListEndpoint(IMapper mapper)
|
||||
{
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public void AddRoute(IEndpointRouteBuilder app)
|
||||
{
|
||||
app.MapGet("api/catalog-brands",
|
||||
async (IRepository<CatalogBrand> catalogBrandRepository) =>
|
||||
{
|
||||
_catalogBrandRepository = catalogBrandRepository;
|
||||
return await HandleAsync();
|
||||
})
|
||||
.Produces<ListCatalogBrandsResponse>()
|
||||
.WithTags("CatalogBrandEndpoints");
|
||||
}
|
||||
|
||||
public async Task<IResult> HandleAsync()
|
||||
{
|
||||
var response = new ListCatalogBrandsResponse();
|
||||
|
||||
var items = await _catalogBrandRepository.ListAsync();
|
||||
|
||||
response.CatalogBrands.AddRange(items.Select(_mapper.Map<CatalogBrandDto>));
|
||||
|
||||
return Results.Ok(response);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Ardalis.ApiEndpoints;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace Microsoft.eShopWeb.PublicApi.CatalogBrandEndpoints;
|
||||
|
||||
public class List : EndpointBaseAsync
|
||||
.WithoutRequest
|
||||
.WithActionResult<ListCatalogBrandsResponse>
|
||||
{
|
||||
private readonly IRepository<CatalogBrand> _catalogBrandRepository;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public List(IRepository<CatalogBrand> catalogBrandRepository,
|
||||
IMapper mapper)
|
||||
{
|
||||
_catalogBrandRepository = catalogBrandRepository;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
[HttpGet("api/catalog-brands")]
|
||||
[SwaggerOperation(
|
||||
Summary = "List Catalog Brands",
|
||||
Description = "List Catalog Brands",
|
||||
OperationId = "catalog-brands.List",
|
||||
Tags = new[] { "CatalogBrandEndpoints" })
|
||||
]
|
||||
public override async Task<ActionResult<ListCatalogBrandsResponse>> HandleAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new ListCatalogBrandsResponse();
|
||||
|
||||
var items = await _catalogBrandRepository.ListAsync(cancellationToken);
|
||||
|
||||
response.CatalogBrands.AddRange(items.Select(_mapper.Map<CatalogBrandDto>));
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user