From 4176ec51704b580828ed21b0173273d4ad400f5c Mon Sep 17 00:00:00 2001 From: PascalMarchesseault <97350299+PascalMarchesseault@users.noreply.github.com> Date: Mon, 11 Nov 2024 11:15:35 -0500 Subject: [PATCH] Il reste a faire la migration! Je ne suis pas capable. --- src/Web/Features/Contents/Data/Content.cs | 5 ++++- src/Web/Features/Contents/Data/ContentDbContext.cs | 7 +++++++ src/Web/Features/Contents/Handlers/CreateContent.cs | 9 ++++++++- .../Features/Contents/Handlers/CreateContentFromHtml.cs | 1 + src/Web/Features/Contents/Handlers/GetContent.cs | 1 + .../Features/Contents/Handlers/GetContentsByCreator.cs | 1 + .../Features/Contents/Handlers/GetFeaturedContents.cs | 1 + .../Features/Contents/Handlers/Models/ContentModel.cs | 1 + 8 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Web/Features/Contents/Data/Content.cs b/src/Web/Features/Contents/Data/Content.cs index 307591c..c9f5dfc 100644 --- a/src/Web/Features/Contents/Data/Content.cs +++ b/src/Web/Features/Contents/Data/Content.cs @@ -11,8 +11,11 @@ public class Content public Guid? DeletedBy { get; set; } public DateTimeOffset? DeletedAt { get; set; } [MaxLength(128)] public required string Title { get; set; } + + [MaxLength(512)]public string? ThumbnailUrl { get; init; } [MaxLength(2048)] public string Description { get; set; } = ""; [MaxLength(2048)] public string? HtmlFileUrl { get; set; } = ""; public IList Reactions { get; set; } = new List(); - public string[]? Urls { get; init; } + public string[]? Urls { get; init; } + } diff --git a/src/Web/Features/Contents/Data/ContentDbContext.cs b/src/Web/Features/Contents/Data/ContentDbContext.cs index f72432f..9dd3c57 100644 --- a/src/Web/Features/Contents/Data/ContentDbContext.cs +++ b/src/Web/Features/Contents/Data/ContentDbContext.cs @@ -30,6 +30,11 @@ public class ContentDbContext( .OwnsMany(c => c.Reactions) .ToTable("Reactions"); + modelBuilder + .Entity() + .Property(c => c.ThumbnailUrl); + + modelBuilder .Entity() .OwnsOne(x => x.Socials) @@ -44,5 +49,7 @@ public class ContentDbContext( .Entity() .OwnsOne(x => x.Images) .ToTable(nameof(Images)); + + } } diff --git a/src/Web/Features/Contents/Handlers/CreateContent.cs b/src/Web/Features/Contents/Handlers/CreateContent.cs index d89f5e7..968c948 100644 --- a/src/Web/Features/Contents/Handlers/CreateContent.cs +++ b/src/Web/Features/Contents/Handlers/CreateContent.cs @@ -14,8 +14,10 @@ public record PostContentRequest( string Title, string Description, IFormFileCollection? Files, + string ThumbnailUrl, string[]? ExternalUrls); + [PublicAPI] public sealed class PostContentRequestValidator : Validator { @@ -40,6 +42,8 @@ public sealed class PostContentRequestValidator : Validator RuleForEach(r => r.ExternalUrls) .NotEmpty().WithMessage("External URL cannot be empty") .Must(url => Uri.IsWellFormedUriString(url, UriKind.Absolute)).WithMessage("External URL is not valid"); + + } } @@ -102,7 +106,9 @@ public sealed class PostContent( CreatedBy = User.GetUserId(), Title = req.Title, Description = req.Description, - Urls = urls.IsEmpty ? null : urls.ToArray() + Urls = urls.IsEmpty ? null : urls.ToArray(), + ThumbnailUrl = req.ThumbnailUrl, + }, ct); @@ -122,6 +128,7 @@ public sealed class PostContent( Title = c.Title, Description = c.Description, Urls = c.Urls, + ThumbnailUrl = c.ThumbnailUrl, }) .SingleOrDefaultAsync( c => c.Id == req.Id, diff --git a/src/Web/Features/Contents/Handlers/CreateContentFromHtml.cs b/src/Web/Features/Contents/Handlers/CreateContentFromHtml.cs index a09a39b..f07ccc2 100644 --- a/src/Web/Features/Contents/Handlers/CreateContentFromHtml.cs +++ b/src/Web/Features/Contents/Handlers/CreateContentFromHtml.cs @@ -75,6 +75,7 @@ public sealed class PostContentHtml( Title = c.Title, Description = c.Description, Urls = c.Urls, + ThumbnailUrl = c.ThumbnailUrl, HtmlFileUrl = htmlFileUrl }) .SingleOrDefaultAsync( diff --git a/src/Web/Features/Contents/Handlers/GetContent.cs b/src/Web/Features/Contents/Handlers/GetContent.cs index 5bae8b6..7ff4ea7 100644 --- a/src/Web/Features/Contents/Handlers/GetContent.cs +++ b/src/Web/Features/Contents/Handlers/GetContent.cs @@ -40,6 +40,7 @@ public class GetContent( Title = c.Title, Description = c.Description, Urls = c.Urls, + ThumbnailUrl = c.ThumbnailUrl, HtmlFileUrl = c.HtmlFileUrl ?? "", Reactions = c.Reactions.Select(x => new ReactionModel { diff --git a/src/Web/Features/Contents/Handlers/GetContentsByCreator.cs b/src/Web/Features/Contents/Handlers/GetContentsByCreator.cs index 5a48d0c..e502e8e 100644 --- a/src/Web/Features/Contents/Handlers/GetContentsByCreator.cs +++ b/src/Web/Features/Contents/Handlers/GetContentsByCreator.cs @@ -51,6 +51,7 @@ public class GetContentsByCreatorHandler( Title = c.Title, Description = c.Description, Urls = c.Urls, + ThumbnailUrl = c.ThumbnailUrl, HtmlFileUrl = c.HtmlFileUrl ?? "", Reactions = c.Reactions.Select(x => new ReactionModel { diff --git a/src/Web/Features/Contents/Handlers/GetFeaturedContents.cs b/src/Web/Features/Contents/Handlers/GetFeaturedContents.cs index 0929503..0a32f88 100644 --- a/src/Web/Features/Contents/Handlers/GetFeaturedContents.cs +++ b/src/Web/Features/Contents/Handlers/GetFeaturedContents.cs @@ -50,6 +50,7 @@ public class GetFeaturedContentsHandler( Title = c.Title, Description = c.Description, Urls = c.Urls, + ThumbnailUrl = c.ThumbnailUrl, Reactions = c.Reactions.Select(x => new ReactionModel { Reaction = x.Reaction.FromEnum(), diff --git a/src/Web/Features/Contents/Handlers/Models/ContentModel.cs b/src/Web/Features/Contents/Handlers/Models/ContentModel.cs index e053c53..b063c2e 100644 --- a/src/Web/Features/Contents/Handlers/Models/ContentModel.cs +++ b/src/Web/Features/Contents/Handlers/Models/ContentModel.cs @@ -14,5 +14,6 @@ public class ContentModel public required string Description { get; init; } public string HtmlFileUrl { get; init; } = ""; public required string[]? Urls { get; init; } + public string? ThumbnailUrl { get; init; } public IList? Reactions { get; set; } = new List(); }