Merging with remote master
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Ardalis.GuardClauses" Version="1.5.0" />
|
<PackageReference Include="Ardalis.GuardClauses" Version="1.5.0" />
|
||||||
<PackageReference Include="Ardalis.Specification" Version="3.0.0" />
|
<PackageReference Include="Ardalis.Specification" Version="3.0.0" />
|
||||||
|
<PackageReference Include="MediatR" Version="8.0.2" />
|
||||||
<PackageReference Include="System.Security.Claims" Version="4.3.0" />
|
<PackageReference Include="System.Security.Claims" Version="4.3.0" />
|
||||||
<PackageReference Include="System.Text.Json" Version="4.7.2" />
|
<PackageReference Include="System.Text.Json" Version="4.7.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
using Ardalis.GuardClauses;
|
using Ardalis.GuardClauses;
|
||||||
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
||||||
using System.Security.Cryptography;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Microsoft.eShopWeb.ApplicationCore.Entities
|
namespace Microsoft.eShopWeb.ApplicationCore.Entities
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public class CatalogItem : BaseEntity, IAggregateRoot
|
public class CatalogItem : BaseEntity, IAggregateRoot
|
||||||
{
|
{
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
@@ -30,18 +32,12 @@ namespace Microsoft.eShopWeb.ApplicationCore.Entities
|
|||||||
PictureUri = pictureUri;
|
PictureUri = pictureUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(string name, decimal price)
|
|
||||||
{
|
|
||||||
Guard.Against.NullOrEmpty(name, nameof(name));
|
|
||||||
Name = name;
|
|
||||||
Price = price;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateDetails(string name, string description, decimal price)
|
public void UpdateDetails(string name, string description, decimal price)
|
||||||
{
|
{
|
||||||
Guard.Against.NullOrEmpty(name, nameof(name));
|
Guard.Against.NullOrEmpty(name, nameof(name));
|
||||||
Guard.Against.NullOrEmpty(description, nameof(description));
|
Guard.Against.NullOrEmpty(description, nameof(description));
|
||||||
Guard.Against.NegativeOrZero(price, nameof(price));
|
Guard.Against.NegativeOrZero(price, nameof(price));
|
||||||
|
|
||||||
Name = name;
|
Name = name;
|
||||||
Description = description;
|
Description = description;
|
||||||
Price = price;
|
Price = price;
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Microsoft.eShopWeb.ApplicationCore.Exceptions
|
||||||
|
{
|
||||||
|
public class DuplicateCatalogItemNameException : Exception
|
||||||
|
{
|
||||||
|
public DuplicateCatalogItemNameException(string message, int duplicateItemId) : base(message)
|
||||||
|
{
|
||||||
|
DuplicateItemId = duplicateItemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int DuplicateItemId { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,8 +4,10 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.eShopWeb.ApplicationCore.Constants;
|
using Microsoft.eShopWeb.ApplicationCore.Constants;
|
||||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||||
|
using Microsoft.eShopWeb.ApplicationCore.Exceptions;
|
||||||
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
||||||
using Swashbuckle.AspNetCore.Annotations;
|
using Swashbuckle.AspNetCore.Annotations;
|
||||||
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Ardalis.ApiEndpoints" Version="1.0.0" />
|
<PackageReference Include="Ardalis.ApiEndpoints" Version="1.0.0" />
|
||||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
|
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
|
||||||
|
<PackageReference Include="MediatR" Version="8.0.2" />
|
||||||
|
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.0.1" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.5.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.5.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.5.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.5.0" />
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
|
using MediatR;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
@@ -8,6 +11,7 @@ using Microsoft.AspNetCore.Hosting;
|
|||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.eShopWeb.ApplicationCore.Constants;
|
using Microsoft.eShopWeb.ApplicationCore.Constants;
|
||||||
|
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||||
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
||||||
using Microsoft.eShopWeb.ApplicationCore.Services;
|
using Microsoft.eShopWeb.ApplicationCore.Services;
|
||||||
using Microsoft.eShopWeb.Infrastructure.Data;
|
using Microsoft.eShopWeb.Infrastructure.Data;
|
||||||
@@ -119,9 +123,9 @@ namespace Microsoft.eShopWeb.PublicApi
|
|||||||
|
|
||||||
|
|
||||||
services.AddControllers();
|
services.AddControllers();
|
||||||
|
services.AddMediatR(typeof(CatalogItem).Assembly);
|
||||||
|
|
||||||
services.AddAutoMapper(typeof(Startup).Assembly);
|
services.AddAutoMapper(typeof(Startup).Assembly);
|
||||||
|
|
||||||
services.AddSwaggerGen(c =>
|
services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
|
||||||
@@ -157,7 +161,6 @@ namespace Microsoft.eShopWeb.PublicApi
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace Microsoft.eShopWeb.Web.Services
|
|||||||
public async Task UpdateCatalogItem(CatalogItemViewModel viewModel)
|
public async Task UpdateCatalogItem(CatalogItemViewModel viewModel)
|
||||||
{
|
{
|
||||||
var existingCatalogItem = await _catalogItemRepository.GetByIdAsync(viewModel.Id);
|
var existingCatalogItem = await _catalogItemRepository.GetByIdAsync(viewModel.Id);
|
||||||
existingCatalogItem.Update(viewModel.Name, viewModel.Price);
|
existingCatalogItem.UpdateDetails(viewModel.Name, existingCatalogItem.Description, viewModel.Price);
|
||||||
await _catalogItemRepository.UpdateAsync(existingCatalogItem);
|
await _catalogItemRepository.UpdateAsync(existingCatalogItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,8 @@
|
|||||||
<PackageReference Include="Ardalis.Specification" Version="3.0.0" />
|
<PackageReference Include="Ardalis.Specification" Version="3.0.0" />
|
||||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
|
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
|
||||||
|
|
||||||
<PackageReference Include="MediatR" Version="8.0.1" />
|
<PackageReference Include="MediatR" Version="8.0.2" />
|
||||||
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.0.0" />
|
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.0.1" />
|
||||||
<PackageReference Include="BuildBundlerMinifier" Version="2.9.406" Condition="'$(Configuration)'=='Release'" PrivateAssets="All" />
|
<PackageReference Include="BuildBundlerMinifier" Version="2.9.406" Condition="'$(Configuration)'=='Release'" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis" Version="3.6.0" />
|
<PackageReference Include="Microsoft.CodeAnalysis" Version="3.6.0" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.5" />
|
||||||
|
|||||||
@@ -1,16 +1,12 @@
|
|||||||
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
|
using Xunit;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.eShopWeb.UnitTests.Builders;
|
|
||||||
using Xunit;
|
|
||||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.OrderTests
|
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.CatalogItemTests
|
||||||
{
|
{
|
||||||
public class UpdateDetails
|
public class UpdateDetails
|
||||||
{
|
{
|
||||||
private CatalogItem _testItem;
|
private CatalogItem _testItem;
|
||||||
private decimal _testUnitPrice = 42m;
|
|
||||||
private int _validTypeId = 1;
|
private int _validTypeId = 1;
|
||||||
private int _validBrandId = 2;
|
private int _validBrandId = 2;
|
||||||
private string _validDescription = "test description";
|
private string _validDescription = "test description";
|
||||||
|
|||||||
Reference in New Issue
Block a user