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