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:
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user