Update to latest Endpoints package and fix breaking changes (#506)

This commit is contained in:
Steve Smith
2021-02-13 10:50:31 -05:00
committed by GitHub
parent 5aa3993c84
commit ba9aea29bd
11 changed files with 56 additions and 39 deletions

View File

@@ -1,39 +1,39 @@
using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.eShopWeb.ApplicationCore.Interfaces;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate namespace Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate
{ {
public class Basket : BaseEntity, IAggregateRoot public class Basket : BaseEntity, IAggregateRoot
{ {
public string BuyerId { get; private set; } public string BuyerId { get; private set; }
private readonly List<BasketItem> _items = new List<BasketItem>(); private readonly List<BasketItem> _items = new List<BasketItem>();
public IReadOnlyCollection<BasketItem> Items => _items.AsReadOnly(); public IReadOnlyCollection<BasketItem> Items => _items.AsReadOnly();
public Basket(string buyerId) public Basket(string buyerId)
{ {
BuyerId = buyerId; BuyerId = buyerId;
} }
public void AddItem(int catalogItemId, decimal unitPrice, int quantity = 1) public void AddItem(int catalogItemId, decimal unitPrice, int quantity = 1)
{ {
if (!Items.Any(i => i.CatalogItemId == catalogItemId)) if (!Items.Any(i => i.CatalogItemId == catalogItemId))
{ {
_items.Add(new BasketItem(catalogItemId, quantity, unitPrice)); _items.Add(new BasketItem(catalogItemId, quantity, unitPrice));
return; return;
} }
var existingItem = Items.FirstOrDefault(i => i.CatalogItemId == catalogItemId); var existingItem = Items.FirstOrDefault(i => i.CatalogItemId == catalogItemId);
existingItem.AddQuantity(quantity); existingItem.AddQuantity(quantity);
} }
public void RemoveEmptyItems() public void RemoveEmptyItems()
{ {
_items.RemoveAll(i => i.Quantity == 0); _items.RemoveAll(i => i.Quantity == 0);
} }
public void SetNewBuyerId(string buyerId) public void SetNewBuyerId(string buyerId)
{ {
BuyerId = buyerId; BuyerId = buyerId;
} }
} }
} }

View File

@@ -8,6 +8,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="BlazorInputFile" Version="0.2.0" /> <PackageReference Include="BlazorInputFile" Version="0.2.0" />
<PackageReference Include="FluentValidation" Version="9.3.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -9,7 +9,9 @@ using System.Threading.Tasks;
namespace Microsoft.eShopWeb.PublicApi.AuthEndpoints namespace Microsoft.eShopWeb.PublicApi.AuthEndpoints
{ {
public class Authenticate : BaseAsyncEndpoint<AuthenticateRequest, AuthenticateResponse> public class Authenticate : BaseAsyncEndpoint
.WithRequest<AuthenticateRequest>
.WithResponse<AuthenticateResponse>
{ {
private readonly SignInManager<ApplicationUser> _signInManager; private readonly SignInManager<ApplicationUser> _signInManager;
private readonly ITokenClaimsService _tokenClaimsService; private readonly ITokenClaimsService _tokenClaimsService;

View File

@@ -10,7 +10,9 @@ using System.Threading.Tasks;
namespace Microsoft.eShopWeb.PublicApi.CatalogBrandEndpoints namespace Microsoft.eShopWeb.PublicApi.CatalogBrandEndpoints
{ {
public class List : BaseAsyncEndpoint<ListCatalogBrandsResponse> public class List : BaseAsyncEndpoint
.WithoutRequest
.WithResponse<ListCatalogBrandsResponse>
{ {
private readonly IAsyncRepository<CatalogBrand> _catalogBrandRepository; private readonly IAsyncRepository<CatalogBrand> _catalogBrandRepository;
private readonly IMapper _mapper; private readonly IMapper _mapper;

View File

@@ -13,7 +13,9 @@ namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
{ {
[Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS, AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] [Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS, AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class Create : BaseAsyncEndpoint<CreateCatalogItemRequest, CreateCatalogItemResponse> public class Create : BaseAsyncEndpoint
.WithRequest<CreateCatalogItemRequest>
.WithResponse<CreateCatalogItemResponse>
{ {
private readonly IAsyncRepository<CatalogItem> _itemRepository; private readonly IAsyncRepository<CatalogItem> _itemRepository;
private readonly IUriComposer _uriComposer; private readonly IUriComposer _uriComposer;

View File

@@ -11,7 +11,9 @@ using System.Threading.Tasks;
namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
{ {
[Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS, AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] [Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS, AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class Delete : BaseAsyncEndpoint<DeleteCatalogItemRequest, DeleteCatalogItemResponse> public class Delete : BaseAsyncEndpoint
.WithRequest<DeleteCatalogItemRequest>
.WithResponse<DeleteCatalogItemResponse>
{ {
private readonly IAsyncRepository<CatalogItem> _itemRepository; private readonly IAsyncRepository<CatalogItem> _itemRepository;

View File

@@ -8,7 +8,9 @@ using System.Threading.Tasks;
namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
{ {
public class GetById : BaseAsyncEndpoint<GetByIdCatalogItemRequest, GetByIdCatalogItemResponse> public class GetById : BaseAsyncEndpoint
.WithRequest<GetByIdCatalogItemRequest>
.WithResponse<GetByIdCatalogItemResponse>
{ {
private readonly IAsyncRepository<CatalogItem> _itemRepository; private readonly IAsyncRepository<CatalogItem> _itemRepository;
private readonly IUriComposer _uriComposer; private readonly IUriComposer _uriComposer;

View File

@@ -12,7 +12,9 @@ using System.Threading.Tasks;
namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
{ {
public class ListPaged : BaseAsyncEndpoint<ListPagedCatalogItemRequest, ListPagedCatalogItemResponse> public class ListPaged : BaseAsyncEndpoint
.WithRequest<ListPagedCatalogItemRequest>
.WithResponse<ListPagedCatalogItemResponse>
{ {
private readonly IAsyncRepository<CatalogItem> _itemRepository; private readonly IAsyncRepository<CatalogItem> _itemRepository;
private readonly IUriComposer _uriComposer; private readonly IUriComposer _uriComposer;

View File

@@ -12,7 +12,9 @@ using System.Threading.Tasks;
namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
{ {
[Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS, AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] [Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS, AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class Update : BaseAsyncEndpoint<UpdateCatalogItemRequest, UpdateCatalogItemResponse> public class Update : BaseAsyncEndpoint
.WithRequest<UpdateCatalogItemRequest>
.WithResponse<UpdateCatalogItemResponse>
{ {
private readonly IAsyncRepository<CatalogItem> _itemRepository; private readonly IAsyncRepository<CatalogItem> _itemRepository;
private readonly IUriComposer _uriComposer; private readonly IUriComposer _uriComposer;

View File

@@ -10,7 +10,9 @@ using System.Threading.Tasks;
namespace Microsoft.eShopWeb.PublicApi.CatalogTypeEndpoints namespace Microsoft.eShopWeb.PublicApi.CatalogTypeEndpoints
{ {
public class List : BaseAsyncEndpoint<ListCatalogTypesResponse> public class List : BaseAsyncEndpoint
.WithoutRequest
.WithResponse<ListCatalogTypesResponse>
{ {
private readonly IAsyncRepository<CatalogType> _catalogTypeRepository; private readonly IAsyncRepository<CatalogType> _catalogTypeRepository;
private readonly IMapper _mapper; private readonly IMapper _mapper;

View File

@@ -9,7 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Ardalis.ApiEndpoints" Version="2.0.0" /> <PackageReference Include="Ardalis.ApiEndpoints" Version="3.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.0" /> <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.0" />
<PackageReference Include="MediatR" Version="9.0.0" /> <PackageReference Include="MediatR" Version="9.0.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" /> <PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />