feat: invites
This commit is contained in:
@@ -14,7 +14,11 @@ public sealed class Collection
|
||||
private readonly List<IDomainEvent> _domainEvents = [];
|
||||
|
||||
public Guid Id { get; private set; }
|
||||
public long OwnerTelegramId { get; private set; }
|
||||
|
||||
/// <summary>Вычисляется из CollectionMember с ролью Owner.</summary>
|
||||
public long OwnerTelegramId =>
|
||||
_members.FirstOrDefault(m => m.Role == CollectionRole.Owner)?.TelegramId ?? 0L;
|
||||
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
public string? Description { get; private set; }
|
||||
public CollectionVisibility Visibility { get; private set; }
|
||||
@@ -37,7 +41,6 @@ public sealed class Collection
|
||||
private Collection(Guid id, long ownerTelegramId, string name, string? description, bool isInbox)
|
||||
{
|
||||
Id = id;
|
||||
OwnerTelegramId = ownerTelegramId;
|
||||
Name = name;
|
||||
Description = description;
|
||||
IsInbox = isInbox;
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
using MemeVault.Domain.Enums;
|
||||
using MemeVault.Domain.Exceptions;
|
||||
|
||||
namespace MemeVault.Domain.Aggregates.CollectionInvite;
|
||||
|
||||
/// <summary>
|
||||
/// Инвайт-ссылка для доступа к коллекции.
|
||||
/// Активна до явного отзыва владельцем.
|
||||
/// Token используется как часть Telegram deep link: t.me/Bot?start=inv_TOKEN
|
||||
/// </summary>
|
||||
public sealed class CollectionInvite
|
||||
{
|
||||
public Guid Id { get; private set; }
|
||||
public Guid CollectionId { get; private set; }
|
||||
public long CreatedByTelegramId { get; private set; }
|
||||
|
||||
/// <summary>Роль, которая будет назначена принявшему инвайт (Viewer или Manager).</summary>
|
||||
public CollectionRole Role { get; private set; }
|
||||
|
||||
/// <summary>Уникальный токен для deep link.</summary>
|
||||
public string Token { get; private set; } = string.Empty;
|
||||
|
||||
public DateTimeOffset CreatedAt { get; private set; }
|
||||
public bool IsRevoked { get; private set; }
|
||||
public DateTimeOffset? RevokedAt { get; private set; }
|
||||
|
||||
// EF Core constructor
|
||||
private CollectionInvite() { }
|
||||
|
||||
private CollectionInvite(Guid collectionId, long createdBy, CollectionRole role)
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
CollectionId = collectionId;
|
||||
CreatedByTelegramId = createdBy;
|
||||
Role = role;
|
||||
Token = GenerateToken();
|
||||
CreatedAt = DateTimeOffset.UtcNow;
|
||||
IsRevoked = false;
|
||||
}
|
||||
|
||||
public static CollectionInvite Create(Guid collectionId, long createdBy, CollectionRole role)
|
||||
{
|
||||
if (role == CollectionRole.Owner)
|
||||
throw new DomainException("Cannot create an invite with Owner role.");
|
||||
|
||||
return new CollectionInvite(collectionId, createdBy, role);
|
||||
}
|
||||
|
||||
public void Revoke()
|
||||
{
|
||||
if (IsRevoked)
|
||||
throw new DomainException("Invite is already revoked.");
|
||||
|
||||
IsRevoked = true;
|
||||
RevokedAt = DateTimeOffset.UtcNow;
|
||||
}
|
||||
|
||||
private static string GenerateToken() =>
|
||||
Convert.ToBase64String(Guid.NewGuid().ToByteArray())
|
||||
.Replace("/", "_").Replace("+", "-").TrimEnd('=');
|
||||
}
|
||||
Reference in New Issue
Block a user