Add catalogitem update endpoint to public api (#418)

* Initial update endpoint working

* Updated CatalogItem to support more updates; added tests

* Got MediatR domain events working to check for duplicate item names

* Adding reference link

* Remove domain events spike code

* clean up usings
This commit is contained in:
Steve Smith
2020-07-10 11:50:46 -04:00
committed by GitHub
parent f89c20ee64
commit 1c75f08a33
13 changed files with 205 additions and 7 deletions

View File

@@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="Ardalis.GuardClauses" Version="1.5.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.Text.Json" Version="4.7.2" />
</ItemGroup>

View File

@@ -1,8 +1,11 @@
using Ardalis.GuardClauses;
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
using System.Collections.Generic;
namespace Microsoft.eShopWeb.ApplicationCore.Entities
{
public class CatalogItem : BaseEntity, IAggregateRoot
{
public string Name { get; private set; }
@@ -14,7 +17,12 @@ namespace Microsoft.eShopWeb.ApplicationCore.Entities
public int CatalogBrandId { get; private set; }
public CatalogBrand CatalogBrand { get; private set; }
public CatalogItem(int catalogTypeId, int catalogBrandId, string description, string name, decimal price, string pictureUri)
public CatalogItem(int catalogTypeId,
int catalogBrandId,
string description,
string name,
decimal price,
string pictureUri)
{
CatalogTypeId = catalogTypeId;
CatalogBrandId = catalogBrandId;
@@ -24,11 +32,27 @@ namespace Microsoft.eShopWeb.ApplicationCore.Entities
PictureUri = pictureUri;
}
public void Update(string name, decimal price)
public void UpdateDetails(string name, string description, decimal price)
{
Guard.Against.NullOrEmpty(name, nameof(name));
Guard.Against.NullOrEmpty(description, nameof(description));
Guard.Against.NegativeOrZero(price, nameof(price));
Name = name;
Description = description;
Price = price;
}
public void UpdateBrand(int catalogBrandId)
{
Guard.Against.Zero(catalogBrandId, nameof(catalogBrandId));
CatalogBrandId = catalogBrandId;
}
public void UpdateType(int catalogTypeId)
{
Guard.Against.Zero(catalogTypeId, nameof(catalogTypeId));
CatalogTypeId = catalogTypeId;
}
}
}

View File

@@ -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; }
}
}