too many changes

This commit is contained in:
2026-10-07 02:17:30 +04:00
parent 0c7f3bce90
commit bcf985c17d
74 changed files with 4048 additions and 78 deletions
@@ -26,6 +26,9 @@ public sealed class Collection
/// <summary>Системная коллекция входящих. Нельзя удалить или переименовать.</summary>
public bool IsInbox { get; private set; }
/// <summary>Коллекция содержит контент 18+. Скрывается в inline-режиме.</summary>
public bool IsNsfw { get; private set; }
/// <summary>Токен для доступа по ссылке (для Visibility = LinkOnly и Public).</summary>
public string? ShareToken { get; private set; }
@@ -102,7 +105,15 @@ public sealed class Collection
UpdatedAt = DateTimeOffset.UtcNow;
}
// ── Видимость и шаринг ────────────────────────────────────────────────────
// ── Видимость, NSFW и шаринг ─────────────────────────────────────────────
/// <summary>Устанавливает NSFW-флаг коллекции. Только Owner.</summary>
public void SetNsfw(bool isNsfw, long requestingTelegramId)
{
EnsureRole(requestingTelegramId, CollectionRole.Owner);
IsNsfw = isNsfw;
UpdatedAt = DateTimeOffset.UtcNow;
}
public void SetVisibility(CollectionVisibility visibility, long requestingTelegramId)
{
@@ -132,6 +143,58 @@ public sealed class Collection
UpdatedAt = DateTimeOffset.UtcNow;
}
// ── Удаление ─────────────────────────────────────────────────────────────
/// <summary>
/// Проверяет, что коллекцию можно удалить, и бросает <see cref="DomainException"/> если нет.
/// Фактическое удаление из хранилища выполняет репозиторий.
/// </summary>
public void Delete(long requestingTelegramId)
{
EnsureRole(requestingTelegramId, CollectionRole.Owner);
if (IsInbox)
throw new DomainException("Cannot delete the Inbox collection.");
}
// ── Inbox ─────────────────────────────────────────────────────────────────
/// <summary>
/// Делает коллекцию основной (Inbox). Вызывать только после снятия флага с текущего Inbox.
/// </summary>
public void PromoteToInbox(long requestingTelegramId)
{
EnsureRole(requestingTelegramId, CollectionRole.Owner);
if (IsInbox)
throw new DomainException("Collection is already the Inbox.");
IsInbox = true;
UpdatedAt = DateTimeOffset.UtcNow;
}
/// <summary>Снимает флаг Inbox. Вызывать перед промоцией другой коллекции.</summary>
public void DemoteFromInbox()
{
IsInbox = false;
UpdatedAt = DateTimeOffset.UtcNow;
}
// ── Инвайты ───────────────────────────────────────────────────────────────
/// <summary>
/// Добавляет принимающего инвайт как участника коллекции.
/// Если пользователь уже является участником (или владельцем) — ничего не делает (идемпотентно).
/// Авторизация производится через инвайт-токен, а не через requestingTelegramId.
/// </summary>
/// <returns>true — участник добавлен; false — уже был участником, изменений нет.</returns>
public bool TryAcceptInvite(long acceptingTelegramId, CollectionRole inviteRole)
{
if (GetRole(acceptingTelegramId) is not null)
return false;
_members.Add(new CollectionMember(Id, acceptingTelegramId, inviteRole));
UpdatedAt = DateTimeOffset.UtcNow;
return true;
}
// ── Доступ ────────────────────────────────────────────────────────────────
public bool CanView(long telegramId)
@@ -140,6 +203,13 @@ public sealed class Collection
return _members.Any(m => m.TelegramId == telegramId);
}
/// <summary>Пользователь может добавлять/изменять элементы коллекции (Менеджер или Владелец).</summary>
public bool CanWrite(long telegramId)
{
var role = GetRole(telegramId);
return role is not null && role >= CollectionRole.Manager;
}
public CollectionRole? GetRole(long telegramId) =>
_members.FirstOrDefault(m => m.TelegramId == telegramId)?.Role;
@@ -24,10 +24,16 @@ public sealed class CollectionInvite
public bool IsRevoked { get; private set; }
public DateTimeOffset? RevokedAt { get; private set; }
/// <summary>Дата истечения инвайта. null — инвайт бессрочный (действует до отзыва).</summary>
public DateTimeOffset? ExpiresAt { get; private set; }
/// <summary>Инвайт истёк по сроку (не связан с ручным отзывом).</summary>
public bool IsExpired => ExpiresAt.HasValue && DateTimeOffset.UtcNow > ExpiresAt.Value;
// EF Core constructor
private CollectionInvite() { }
private CollectionInvite(Guid collectionId, long createdBy, CollectionRole role)
private CollectionInvite(Guid collectionId, long createdBy, CollectionRole role, DateTimeOffset? expiresAt)
{
Id = Guid.NewGuid();
CollectionId = collectionId;
@@ -35,15 +41,23 @@ public sealed class CollectionInvite
Role = role;
Token = GenerateToken();
CreatedAt = DateTimeOffset.UtcNow;
ExpiresAt = expiresAt;
IsRevoked = false;
}
public static CollectionInvite Create(Guid collectionId, long createdBy, CollectionRole role)
public static CollectionInvite Create(
Guid collectionId,
long createdBy,
CollectionRole role,
DateTimeOffset? expiresAt = null)
{
if (role == CollectionRole.Owner)
throw new DomainException("Cannot create an invite with Owner role.");
return new CollectionInvite(collectionId, createdBy, role);
if (expiresAt.HasValue && expiresAt.Value <= DateTimeOffset.UtcNow)
throw new DomainException("Invite expiry must be in the future.");
return new CollectionInvite(collectionId, createdBy, role, expiresAt);
}
public void Revoke()
@@ -11,6 +11,7 @@ namespace MemeVault.Domain.Aggregates.MediaItem;
/// </summary>
public sealed class MediaItem
{
// Не readonly: EF Core перезаписывает ссылку при материализации из text[] через value conversion.
private List<Tag> _tags = [];
private readonly List<IDomainEvent> _domainEvents = [];
@@ -122,5 +123,17 @@ public sealed class MediaItem
UpdatedAt = DateTimeOffset.UtcNow;
}
/// <summary>Полностью заменяет набор тегов. Дубли игнорируются. Лимит — 20 тегов.</summary>
public void ReplaceTags(IEnumerable<Tag> newTags)
{
var distinct = newTags.Distinct().ToList();
if (distinct.Count > 20)
throw new DomainException("Cannot have more than 20 tags per item.");
_tags.Clear();
_tags.AddRange(distinct);
UpdatedAt = DateTimeOffset.UtcNow;
}
public void ClearDomainEvents() => _domainEvents.Clear();
}