post reactions

This commit is contained in:
john 2025-05-28 22:05:20 +02:00
parent d1687f276b
commit 8e8e4e2258
10 changed files with 124 additions and 8 deletions

View file

@ -14,7 +14,7 @@ internal class Post : Entity
public IList<PostReaction> Reactions { get; private set; } = [];
public bool IsPublic { get; set; }
public DateTimeOffset PostedOn { get; private set; }
private string PossibleReactionsJson { get; set; } = null!;
@ -38,4 +38,22 @@ internal class Post : Entity
this.AddDomainEvent(new PostCreated(this));
}
public void AddReaction(Guid reactorId, string emoji)
{
if (!this.PossibleReactions.Contains(emoji))
return;
if (this.Reactions.Any(r => r.AuthorId == reactorId && r.Emoji == emoji))
return;
this.Reactions.Add(new PostReaction(reactorId, this.Id, emoji));
}
public void RemoveReaction(Guid reactorId, string emoji)
{
this.Reactions = this
.Reactions.Where(r => r.AuthorId != reactorId || r.Emoji != emoji)
.ToList();
}
}