Change CreateContent to allows content without images
This commit is contained in:
@@ -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,38 +53,40 @@ public sealed class PostContent(
|
||||
PostContentRequest req,
|
||||
CancellationToken ct)
|
||||
{
|
||||
|
||||
var urls = new ConcurrentBag<string>();
|
||||
|
||||
await Parallel.ForEachAsync(
|
||||
req.Files,
|
||||
ct,
|
||||
async (file, ict) =>
|
||||
{
|
||||
try
|
||||
if (req.Files is not null)
|
||||
{
|
||||
await Parallel.ForEachAsync(
|
||||
req.Files,
|
||||
ct,
|
||||
async (file, ict) =>
|
||||
{
|
||||
var contentUrl = await SaveFileAsync(
|
||||
req.CreatorId,
|
||||
req.Id,
|
||||
file,
|
||||
ict);
|
||||
try
|
||||
{
|
||||
var contentUrl = await SaveFileAsync(
|
||||
req.CreatorId,
|
||||
req.Id,
|
||||
file,
|
||||
ict);
|
||||
|
||||
urls.Add(contentUrl);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError("{ErrorMessage}", ex.Message);
|
||||
}
|
||||
});
|
||||
urls.Add(contentUrl);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user