Change CreateContent to allows content without images

This commit is contained in:
2024-08-15 12:38:40 -04:00
parent 256d7b7ff7
commit 536e192ff4

View File

@@ -12,7 +12,7 @@ public record PostContentRequest(
Guid CreatorId,
string Title,
string Description,
IFormFileCollection Files);
IFormFileCollection? Files);
[PublicAPI]
public sealed class PostContentRequestValidator : Validator<PostContentRequest>
@@ -53,9 +53,10 @@ public sealed class PostContent(
PostContentRequest req,
CancellationToken ct)
{
var urls = new ConcurrentBag<string>();
if (req.Files is not null)
{
await Parallel.ForEachAsync(
req.Files,
ct,
@@ -76,15 +77,16 @@ public sealed class PostContent(
Logger.LogError("{ErrorMessage}", ex.Message);
}
});
}
await context.Contents.AddAsync(
new()
new Content
{
Id = req.Id,
CreatedBy = User.GetUserId(),
Title = req.Title,
Description = req.Description,
Urls = urls.ToArray()
Urls = urls.IsEmpty ? null : urls.ToArray()
},
ct);