wip
This commit is contained in:
parent
def7767b94
commit
8ad4302ec8
13 changed files with 3902 additions and 4 deletions
|
@ -10,5 +10,6 @@ internal class PostConfiguration : IEntityTypeConfiguration<Post>
|
|||
{
|
||||
table.ToTable("post");
|
||||
table.OwnsMany(post => post.Media).WithOwner();
|
||||
table.OwnsMany(post => post.Reactions).WithOwner();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
namespace Femto.Modules.Blog.Application.Queries.GetPosts.Dto;
|
||||
|
||||
public record PostDto(Guid PostId, string Text, IList<PostMediaDto> Media, DateTimeOffset CreatedAt, PostAuthorDto Author);
|
||||
public record PostDto(
|
||||
Guid PostId,
|
||||
string Text,
|
||||
IList<PostMediaDto> Media,
|
||||
DateTimeOffset CreatedAt,
|
||||
PostAuthorDto Author,
|
||||
IList<PostReactionDto> Reactions);
|
|
@ -0,0 +1,3 @@
|
|||
namespace Femto.Modules.Blog.Application.Queries.GetPosts.Dto;
|
||||
|
||||
public record PostReactionDto(string Emoji, int Count, bool DidReact);
|
|
@ -1,5 +1,6 @@
|
|||
using Femto.Common.Domain;
|
||||
using Femto.Modules.Blog.Domain.Posts.Events;
|
||||
using Femto.Modules.Blog.Emoji;
|
||||
|
||||
namespace Femto.Modules.Blog.Domain.Posts;
|
||||
|
||||
|
@ -9,6 +10,8 @@ internal class Post : Entity
|
|||
public Guid AuthorId { get; private set; }
|
||||
public string Content { get; private set; } = null!;
|
||||
public IList<PostMedia> Media { get; private set; }
|
||||
|
||||
public IList<PostReaction> Reactions { get; private set; } = [];
|
||||
public bool IsPublic { get; set; }
|
||||
|
||||
private Post() { }
|
||||
|
@ -19,7 +22,13 @@ 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.AddDomainEvent(new PostCreated(this));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
17
Femto.Modules.Blog/Domain/Posts/PostReaction.cs
Normal file
17
Femto.Modules.Blog/Domain/Posts/PostReaction.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
namespace Femto.Modules.Blog.Domain.Posts;
|
||||
|
||||
public class PostReaction
|
||||
{
|
||||
public Guid Id { get; private set; }
|
||||
public string Emoji { get; private set; } = null!;
|
||||
public int Count { get; private set; }
|
||||
|
||||
public PostReaction(string emoji, int count)
|
||||
{
|
||||
this.Id = Guid.CreateVersion7();
|
||||
this.Emoji = emoji;
|
||||
this.Count = count;
|
||||
}
|
||||
|
||||
private PostReaction() { }
|
||||
}
|
18
Femto.Modules.Blog/Emoji/GetRandomEmoji.cs
Normal file
18
Femto.Modules.Blog/Emoji/GetRandomEmoji.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
namespace Femto.Modules.Blog.Emoji;
|
||||
|
||||
internal static partial class AllEmoji
|
||||
{
|
||||
public static IList<string> GetRandomEmoji(int count) => new Random().TakeRandomly(Emojis).Distinct().Take(count).ToList();
|
||||
}
|
||||
|
||||
internal static class RandomExtensions
|
||||
{
|
||||
public static IEnumerable<T> TakeRandomly<T>(this Random rand, ICollection<T> collection)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var idx = rand.Next(collection.Count);
|
||||
yield return collection.ElementAt(idx);
|
||||
}
|
||||
}
|
||||
}
|
3789
Femto.Modules.Blog/Emoji/ListOfEmoji.cs
Normal file
3789
Femto.Modules.Blog/Emoji/ListOfEmoji.cs
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue