category
This commit is contained in:
@@ -28,24 +28,20 @@ public class Category : Entity<CategoryId>
|
||||
private Category(TitleVO title,
|
||||
DescriptionVO description,
|
||||
CategoryImage image,
|
||||
CategoryPath path,
|
||||
CategoryId? parentId = null)
|
||||
{
|
||||
_title = title;
|
||||
_description = description;
|
||||
_image = image;
|
||||
_parentId = parentId;
|
||||
_path = path;
|
||||
|
||||
}
|
||||
|
||||
public static Category CreateNew(TitleVO title,
|
||||
DescriptionVO description,
|
||||
CategoryImage image,
|
||||
CategoryPath path,
|
||||
CategoryId? parentId = null)
|
||||
{
|
||||
return new Category(title, description, image, path, parentId);
|
||||
return new Category(title, description, image, parentId);
|
||||
}
|
||||
|
||||
public TitleVO Title => _title;
|
||||
@@ -55,5 +51,9 @@ public class Category : Entity<CategoryId>
|
||||
public CategoryPath Path => _path;
|
||||
public IReadOnlyList<Product> Products => _products;
|
||||
|
||||
public void SetPath(CategoryPath? parentPath)
|
||||
{
|
||||
_path = CategoryPath.CreatePath(parentPath, Id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Vizhvizh.BuildingBlocks.Domain;
|
||||
using Vizhvizh.GoldGallery.Domain.Products.TypeIds;
|
||||
|
||||
namespace Vizhvizh.GoldGallery.Domain.Products.ValuesObjects;
|
||||
|
||||
@@ -10,15 +11,15 @@ public class CategoryPath : ValueObject
|
||||
Value = value;
|
||||
}
|
||||
public string Value { get; private set; }
|
||||
|
||||
public static CategoryPath CreateNew(string value)
|
||||
=> new CategoryPath(value);
|
||||
=> new(value);
|
||||
|
||||
|
||||
public static CategoryPath CreatePath(CategoryPath? parentPath, string childId)
|
||||
internal static CategoryPath CreatePath(CategoryPath? parentPath, CategoryId childId)
|
||||
{
|
||||
if (parentPath == null)
|
||||
return new CategoryPath(childId);
|
||||
return new CategoryPath($"/{childId.Value}/");
|
||||
|
||||
return new CategoryPath($"{parentPath.Value}/{childId}");
|
||||
return new CategoryPath($"{parentPath.Value}{childId.Value}/");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user