Adds external urls to create content
This commit is contained in:
@@ -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
|
||||
{
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user