Simplify data representation

This commit is contained in:
lumijiez
2025-05-04 20:01:21 +03:00
parent 247bfba368
commit e001ea67a3
12 changed files with 54 additions and 440 deletions

View File

@@ -2,48 +2,8 @@ namespace Printbase.Domain.Entities.Products;
public class ProductGroup
{
public Guid Id { get; private set; }
public string Name { get; private set; }
public string? Description { get; private set; }
public IReadOnlyCollection<ProductType> Types => _types.AsReadOnly();
private readonly List<ProductType> _types = new();
private ProductGroup() { }
public ProductGroup(Guid id, string name, string? description = null)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Group name cannot be empty", nameof(name));
Id = id;
Name = name;
Description = description;
}
public void AddType(ProductType type)
{
ArgumentNullException.ThrowIfNull(type);
_types.Add(type);
}
public void RemoveType(Guid typeId)
{
var type = _types.Find(t => t.Id == typeId);
if (type != null) _types.Remove(type);
}
public void UpdateName(string name)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Group name cannot be empty", nameof(name));
Name = name;
}
public void UpdateDescription(string? description)
{
Description = description;
}
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;
public string? Description { get; set; }
public ICollection<ProductType> Types { get; set; } = [];
}