return postdto from post create

This commit is contained in:
john 2025-05-28 20:05:00 +02:00
parent 8ad4302ec8
commit d1687f276b
15 changed files with 226 additions and 111 deletions

View file

@ -1,3 +1,4 @@
using System.Text.Json;
using Femto.Common.Domain;
using Femto.Modules.Blog.Domain.Posts.Events;
using Femto.Modules.Blog.Emoji;
@ -13,6 +14,16 @@ 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!;
public IEnumerable<string> PossibleReactions
{
get => JsonSerializer.Deserialize<IEnumerable<string>>(this.PossibleReactionsJson)!;
init => PossibleReactionsJson = JsonSerializer.Serialize(value);
}
private Post() { }
@ -22,13 +33,9 @@ internal class Post : Entity
this.AuthorId = authorId;
this.Content = content;
this.Media = media;
this.Reactions = AllEmoji
.GetRandomEmoji(5)
.Select(emoji => new PostReaction(emoji, 0))
.ToList();
this.PossibleReactions = AllEmoji.GetRandomEmoji(5);
this.PostedOn = DateTimeOffset.UtcNow;
this.AddDomainEvent(new PostCreated(this));
}
}