diff --git a/src/Web/Features/Contents/Handlers/CreateContent.cs b/src/Web/Features/Contents/Handlers/CreateContent.cs index 8d01e5c..cd8934a 100644 --- a/src/Web/Features/Contents/Handlers/CreateContent.cs +++ b/src/Web/Features/Contents/Handlers/CreateContent.cs @@ -13,7 +13,8 @@ public record PostContentRequest( Guid CreatorId, string Title, string Description, - IFormFileCollection? Files); + IFormFileCollection? Files, + string[]? ExternalUrls); [PublicAPI] public sealed class PostContentRequestValidator : Validator @@ -35,6 +36,10 @@ public sealed class PostContentRequestValidator : Validator RuleFor(r => r.Description) .NotNull().WithMessage("You should specify the Description") .NotEmpty().WithMessage("You should specify a valid/not empty Description"); + + RuleForEach(r => r.ExternalUrls) + .NotEmpty().WithMessage("External URL cannot be empty") + .Must(url => Uri.IsWellFormedUriString(url, UriKind.Absolute)).WithMessage("External URL is not valid"); } } @@ -61,7 +66,9 @@ public sealed class PostContent( await Parallel.ForEachAsync( req.Files, ct, - async (file, ict) => + async ( + file, + ict) => { try { @@ -79,7 +86,15 @@ public sealed class PostContent( } }); } - + + if (req.ExternalUrls is not null) + { + foreach (var externalUrl in req.ExternalUrls) + { + urls.Add(externalUrl); + } + } + await context.Contents.AddAsync( new Content {