feat: item to collection

This commit is contained in:
2026-09-28 02:37:11 +04:00
parent 5238bfd103
commit 50fe29f4f0
29 changed files with 732 additions and 156 deletions
@@ -6,10 +6,10 @@ namespace MemeVault.Domain.Aggregates.Collection;
/// <summary>
/// Aggregate Root: коллекция медиа-элементов с ACL-моделью доступа.
/// Каждый пользователь имеет ровно одну системную коллекцию Inbox (IsInbox = true).
/// </summary>
public sealed class Collection
{
private readonly List<Guid> _mediaItemIds = [];
private readonly List<CollectionMember> _members = [];
private readonly List<IDomainEvent> _domainEvents = [];
@@ -19,12 +19,12 @@ public sealed class Collection
public string? Description { get; private set; }
public CollectionVisibility Visibility { get; private set; }
/// <summary>
/// Токен для доступа по ссылке (для Visibility = LinkOnly и Public).
/// </summary>
/// <summary>Системная коллекция входящих. Нельзя удалить или переименовать.</summary>
public bool IsInbox { get; private set; }
/// <summary>Токен для доступа по ссылке (для Visibility = LinkOnly и Public).</summary>
public string? ShareToken { get; private set; }
public IReadOnlyList<Guid> MediaItemIds => _mediaItemIds.AsReadOnly();
public IReadOnlyList<CollectionMember> Members => _members.AsReadOnly();
public DateTimeOffset CreatedAt { get; private set; }
public DateTimeOffset? UpdatedAt { get; private set; }
@@ -34,12 +34,13 @@ public sealed class Collection
// EF Core constructor
private Collection() { }
private Collection(Guid id, long ownerTelegramId, string name, string? description)
private Collection(Guid id, long ownerTelegramId, string name, string? description, bool isInbox)
{
Id = id;
OwnerTelegramId = ownerTelegramId;
Name = name;
Description = description;
IsInbox = isInbox;
Visibility = CollectionVisibility.Private;
CreatedAt = DateTimeOffset.UtcNow;
@@ -55,29 +56,12 @@ public sealed class Collection
if (name.Length > 100)
throw new DomainException("Collection name must be 100 characters or less.");
return new Collection(Guid.NewGuid(), ownerTelegramId, name, description);
return new Collection(Guid.NewGuid(), ownerTelegramId, name, description, isInbox: false);
}
// ── Управление элементами ──────────────────────────────────────────────────
public void AddItem(Guid mediaItemId, long requestingTelegramId)
{
EnsureRole(requestingTelegramId, CollectionRole.Manager);
if (_mediaItemIds.Contains(mediaItemId)) return;
if (_mediaItemIds.Count >= 500)
throw new DomainException("Collection cannot have more than 500 items.");
_mediaItemIds.Add(mediaItemId);
UpdatedAt = DateTimeOffset.UtcNow;
}
public void RemoveItem(Guid mediaItemId, long requestingTelegramId)
{
EnsureRole(requestingTelegramId, CollectionRole.Manager);
_mediaItemIds.Remove(mediaItemId);
UpdatedAt = DateTimeOffset.UtcNow;
}
/// <summary>Создаёт системную коллекцию входящих для нового пользователя.</summary>
public static Collection CreateInbox(long ownerTelegramId) =>
new(Guid.NewGuid(), ownerTelegramId, "Inbox", description: null, isInbox: true);
// ── Управление участниками ─────────────────────────────────────────────────
@@ -133,6 +117,9 @@ public sealed class Collection
public void Rename(string newName, long requestingTelegramId)
{
if (IsInbox)
throw new DomainException("Cannot rename the Inbox collection.");
EnsureRole(requestingTelegramId, CollectionRole.Manager);
if (string.IsNullOrWhiteSpace(newName))
@@ -157,8 +144,7 @@ public sealed class Collection
{
var role = GetRole(telegramId);
if (role is null || role < minimumRole)
throw new DomainException(
$"Action requires at least {minimumRole} role.");
throw new DomainException($"Action requires at least {minimumRole} role.");
}
private static string GenerateToken() =>