-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Product and Category to Warehouse Module
- Loading branch information
1 parent
121f24e
commit 3b520c2
Showing
19 changed files
with
302 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace SharedKernel.Domain.Identifiers; | ||
|
||
public record ProductId(Guid Value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 63 additions & 63 deletions
126
src/Modules/Orders/Modules.Orders.Domain/Products/Product.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,63 @@ | ||
using Ardalis.GuardClauses; | ||
|
||
using SharedKernel.Domain.Base; | ||
using SharedKernel.Domain.Entities; | ||
|
||
namespace Modules.Orders.Domain.Products; | ||
|
||
public class Product : AggregateRoot<ProductId> | ||
{ | ||
//public CategoryId CategoryId { get; set; } = null!; | ||
|
||
//public Category Category { get; set; } = null!; | ||
|
||
public string Name { get; private set; } = null!; | ||
|
||
public Money Price { get; private set; } = null!; | ||
|
||
public Sku Sku { get; private set; } = null!; | ||
|
||
private Product() { } | ||
|
||
// NOTE: Need to use a factory, as EF does not let owned entities (i.e Money & Sku) be passed via the constructor | ||
public static Product Create(string name, Money price, Sku sku/*, CategoryId categoryId*/) | ||
{ | ||
Guard.Against.NullOrWhiteSpace(name); | ||
Guard.Against.Null(sku); | ||
Guard.Against.Null(price); | ||
Guard.Against.ZeroOrNegative(price.Amount); | ||
//Guard.Against.Null(categoryId); | ||
|
||
var product = new Product | ||
{ | ||
Id = new ProductId(Guid.NewGuid()), | ||
// CategoryId = categoryId, | ||
Name = name, | ||
Price = price, | ||
Sku = sku | ||
}; | ||
|
||
product.AddDomainEvent(ProductCreatedEvent.Create(product)); | ||
|
||
return product; | ||
} | ||
|
||
public void UpdateName(string name) | ||
{ | ||
Guard.Against.NullOrWhiteSpace(name); | ||
Name = name; | ||
} | ||
|
||
public void UpdatePrice(Money price) | ||
{ | ||
Guard.Against.Null(price); | ||
Guard.Against.ZeroOrNegative(price.Amount); | ||
Price = price; | ||
} | ||
|
||
public void UpdateSku(Sku sku) | ||
{ | ||
Guard.Against.Null(sku); | ||
Sku = sku; | ||
} | ||
} | ||
// using Ardalis.GuardClauses; | ||
// | ||
// using SharedKernel.Domain.Base; | ||
// using SharedKernel.Domain.Entities; | ||
// | ||
// namespace Modules.Orders.Domain.Products; | ||
// | ||
// public class Product : AggregateRoot<ProductId> | ||
// { | ||
// //public CategoryId CategoryId { get; set; } = null!; | ||
// | ||
// //public Category Category { get; set; } = null!; | ||
// | ||
// public string Name { get; private set; } = null!; | ||
// | ||
// public Money Price { get; private set; } = null!; | ||
// | ||
// public Sku Sku { get; private set; } = null!; | ||
// | ||
// private Product() { } | ||
// | ||
// // NOTE: Need to use a factory, as EF does not let owned entities (i.e Money & Sku) be passed via the constructor | ||
// public static Product Create(string name, Money price, Sku sku/*, CategoryId categoryId*/) | ||
// { | ||
// Guard.Against.NullOrWhiteSpace(name); | ||
// Guard.Against.Null(sku); | ||
// Guard.Against.Null(price); | ||
// Guard.Against.ZeroOrNegative(price.Amount); | ||
// //Guard.Against.Null(categoryId); | ||
// | ||
// var product = new Product | ||
// { | ||
// Id = new ProductId(Guid.NewGuid()), | ||
// // CategoryId = categoryId, | ||
// Name = name, | ||
// Price = price, | ||
// Sku = sku | ||
// }; | ||
// | ||
// product.AddDomainEvent(ProductCreatedEvent.Create(product)); | ||
// | ||
// return product; | ||
// } | ||
// | ||
// public void UpdateName(string name) | ||
// { | ||
// Guard.Against.NullOrWhiteSpace(name); | ||
// Name = name; | ||
// } | ||
// | ||
// public void UpdatePrice(Money price) | ||
// { | ||
// Guard.Against.Null(price); | ||
// Guard.Against.ZeroOrNegative(price.Amount); | ||
// Price = price; | ||
// } | ||
// | ||
// public void UpdateSku(Sku sku) | ||
// { | ||
// Guard.Against.Null(sku); | ||
// Sku = sku; | ||
// } | ||
// } |
22 changes: 11 additions & 11 deletions
22
src/Modules/Orders/Modules.Orders.Domain/Products/ProductByIdSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
using Ardalis.Specification; | ||
|
||
namespace Modules.Orders.Domain.Products; | ||
|
||
public class ProductByIdSpec : Specification<Product>, ISingleResultSpecification<Product> | ||
{ | ||
public ProductByIdSpec(ProductId id) : base() | ||
{ | ||
Query.Where(i => i.Id == id); | ||
} | ||
} | ||
// using Ardalis.Specification; | ||
// | ||
// namespace Modules.Orders.Domain.Products; | ||
// | ||
// public class ProductByIdSpec : Specification<Product>, ISingleResultSpecification<Product> | ||
// { | ||
// public ProductByIdSpec(ProductId id) : base() | ||
// { | ||
// Query.Where(i => i.Id == id); | ||
// } | ||
// } |
16 changes: 8 additions & 8 deletions
16
src/Modules/Orders/Modules.Orders.Domain/Products/ProductCreatedEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
using SharedKernel.Domain.Base; | ||
|
||
namespace Modules.Orders.Domain.Products; | ||
|
||
public record ProductCreatedEvent(ProductId Product, string ProductName) : DomainEvent | ||
{ | ||
public static ProductCreatedEvent Create(Product product) => new(product.Id, product.Name); | ||
} | ||
// using SharedKernel.Domain.Base; | ||
// | ||
// namespace Modules.Orders.Domain.Products; | ||
// | ||
// public record ProductCreatedEvent(ProductId Product, string ProductName) : DomainEvent | ||
// { | ||
// public static ProductCreatedEvent Create(Product product) => new(product.Id, product.Name); | ||
// } |
6 changes: 3 additions & 3 deletions
6
src/Modules/Orders/Modules.Orders.Domain/Products/ProductId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
namespace Modules.Orders.Domain.Products; | ||
|
||
public record ProductId(Guid Value); | ||
// namespace Modules.Orders.Domain.Products; | ||
// | ||
// public record ProductId(Guid Value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
namespace Modules.Orders.Domain.Products; | ||
|
||
public record Sku | ||
{ | ||
private const int DefaultLength = 8; | ||
|
||
public string Value { get; } | ||
|
||
private Sku(string value) => Value = value; | ||
|
||
public static Sku? Create(string value) | ||
{ | ||
if (string.IsNullOrWhiteSpace(value)) | ||
return null; | ||
|
||
if (value.Length != DefaultLength) | ||
return null; | ||
|
||
return new Sku(value); | ||
} | ||
} | ||
// namespace Modules.Orders.Domain.Products; | ||
// | ||
// public record Sku | ||
// { | ||
// private const int DefaultLength = 8; | ||
// | ||
// public string Value { get; } | ||
// | ||
// private Sku(string value) => Value = value; | ||
// | ||
// public static Sku? Create(string value) | ||
// { | ||
// if (string.IsNullOrWhiteSpace(value)) | ||
// return null; | ||
// | ||
// if (value.Length != DefaultLength) | ||
// return null; | ||
// | ||
// return new Sku(value); | ||
// } | ||
// } |
38 changes: 38 additions & 0 deletions
38
src/Modules/Warehouse/Modules.Warehouse.Domain/Categories/Category.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Ardalis.GuardClauses; | ||
|
||
using SharedKernel.Domain.Base; | ||
using SharedKernel.Domain.Exceptions; | ||
|
||
namespace Modules.Warehouse.Domain.Categories; | ||
|
||
public class Category : AggregateRoot<CategoryId> | ||
{ | ||
public string Name { get; private set; } = default!; | ||
|
||
private Category() { } | ||
|
||
// NOTE: Need to use a factory, as EF does not let owned entities (i.e Money & Sku) be passed via the constructor | ||
public static Category Create(string name, ICategoryService categoryService) | ||
{ | ||
var category = new Category | ||
{ | ||
Id = new CategoryId(Guid.NewGuid()), | ||
}; | ||
|
||
category.UpdateName(name, categoryService); | ||
|
||
category.AddDomainEvent(new CategoryCreatedEvent(category.Id, category.Name)); | ||
|
||
return category; | ||
} | ||
|
||
public void UpdateName(string name, ICategoryService categoryService) | ||
{ | ||
Guard.Against.NullOrWhiteSpace(name); | ||
|
||
if (categoryService.CategoryExists(name)) | ||
throw new DomainException($"Category {name} already exists"); | ||
|
||
Name = name; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Modules/Warehouse/Modules.Warehouse.Domain/Categories/CategoryByIdSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Ardalis.Specification; | ||
|
||
namespace Modules.Warehouse.Domain.Categories; | ||
|
||
public class CategoryByIdSpec : Specification<Category>, ISingleResultSpecification<Category> | ||
{ | ||
public CategoryByIdSpec(CategoryId id) : base() | ||
{ | ||
Query.Where(i => i.Id == id); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/Modules/Warehouse/Modules.Warehouse.Domain/Categories/CategoryCreatedEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using SharedKernel.Domain.Base; | ||
|
||
namespace Modules.Warehouse.Domain.Categories; | ||
|
||
public record CategoryCreatedEvent(CategoryId Id, string Name) : DomainEvent; |
3 changes: 3 additions & 0 deletions
3
src/Modules/Warehouse/Modules.Warehouse.Domain/Categories/CategoryId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Modules.Warehouse.Domain.Categories; | ||
|
||
public record CategoryId(Guid Value); |
6 changes: 6 additions & 0 deletions
6
src/Modules/Warehouse/Modules.Warehouse.Domain/Categories/ICategoryService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Modules.Warehouse.Domain.Categories; | ||
|
||
public interface ICategoryService | ||
{ | ||
bool CategoryExists(string categoryName); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.