Adds external urls to create content

This commit is contained in:
2024-09-04 15:28:07 -04:00
parent a4a2c96922
commit 1fc6ddaf8d

View File

@@ -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<PostContentRequest>
@@ -35,6 +36,10 @@ public sealed class PostContentRequestValidator : Validator<PostContentRequest>
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
{
@@ -80,6 +87,14 @@ 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
{