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
@@ -1,6 +1,5 @@
using MediatR;
using MemeVault.Application.Common;
using MemeVault.Domain.Enums;
using MemeVault.Domain.Exceptions;
using MemeVault.Domain.Repositories;
@@ -27,25 +26,19 @@ public sealed class AcceptCollectionInviteCommandHandler
AcceptCollectionInviteCommand request, CancellationToken cancellationToken)
{
var invite = await _invites.GetByTokenAsync(request.Token, cancellationToken);
if (invite is null || invite.IsRevoked)
if (invite is null || invite.IsRevoked || invite.IsExpired)
return null;
var collection = await _collections.GetByIdAsync(invite.CollectionId, cancellationToken)
?? throw new DomainException("Collection no longer exists.");
// Владелец не может принять инвайт в собственную коллекцию
if (collection.OwnerTelegramId == request.AcceptingTelegramId)
return collection.Id;
// Если уже участник — просто возвращаем коллекцию (идемпотентность)
if (collection.GetRole(request.AcceptingTelegramId) is not null)
return collection.Id;
// Owner создаёт инвайт с правами requestingTelegramId, добавляем участника
collection.AddMember(request.AcceptingTelegramId, invite.Role, collection.OwnerTelegramId);
await _collections.UpdateAsync(collection, cancellationToken);
await _uow.SaveChangesAsync(cancellationToken);
// Инвариант "уже участник/владелец → идемпотентно" живёт на агрегате.
var added = collection.TryAcceptInvite(request.AcceptingTelegramId, invite.Role);
if (added)
{
await _collections.UpdateAsync(collection, cancellationToken);
await _uow.SaveChangesAsync(cancellationToken);
}
return collection.Id;
}