Change CreateContent to allows content without images
This commit is contained in:
@@ -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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user