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,38 +53,40 @@ public sealed class PostContent(
|
|||||||
PostContentRequest req,
|
PostContentRequest req,
|
||||||
CancellationToken ct)
|
CancellationToken ct)
|
||||||
{
|
{
|
||||||
|
|
||||||
var urls = new ConcurrentBag<string>();
|
var urls = new ConcurrentBag<string>();
|
||||||
|
|
||||||
await Parallel.ForEachAsync(
|
if (req.Files is not null)
|
||||||
req.Files,
|
{
|
||||||
ct,
|
await Parallel.ForEachAsync(
|
||||||
async (file, ict) =>
|
req.Files,
|
||||||
{
|
ct,
|
||||||
try
|
async (file, ict) =>
|
||||||
{
|
{
|
||||||
var contentUrl = await SaveFileAsync(
|
try
|
||||||
req.CreatorId,
|
{
|
||||||
req.Id,
|
var contentUrl = await SaveFileAsync(
|
||||||
file,
|
req.CreatorId,
|
||||||
ict);
|
req.Id,
|
||||||
|
file,
|
||||||
|
ict);
|
||||||
|
|
||||||
urls.Add(contentUrl);
|
urls.Add(contentUrl);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
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