Skip to content

Commit

Permalink
VCST-2523: Some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Ljutyj committed Jan 10, 2025
1 parent da9d62c commit 45cfa14
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,33 @@ public async Task<CreateReviewResult> Handle(CreateReviewCommand request, Cancel
review.UserName = contact?.FullName ?? currentUser.UserName;
}

IList<File> files = null;
if (!request.ImageUrls.IsNullOrEmpty())
{
files = await SaveImages(request, review);
}

await _reviewService.SaveChangesAsync([review]);

response.Id = review.Id;
response.UserName = review.UserName;

await SaveImages(request, review);
if (files.Count > 0)
{
foreach (var file in files)
{
file.OwnerEntityId = review.Id;
file.OwnerEntityType = nameof(CustomerReview);
}

await _reviewService.SaveChangesAsync([review]);
await _fileUploadService.SaveChangesAsync(files);
}
}

return response;
}

protected virtual async Task SaveImages(CreateReviewCommand request, CustomerReview review)
protected virtual async Task<IList<File>> SaveImages(CreateReviewCommand request, CustomerReview review)
{
var files = await GetFiles(request.ImageUrls);
var filesByUrls = files
Expand All @@ -101,17 +114,11 @@ protected virtual async Task SaveImages(CreateReviewCommand request, CustomerRev
if (filesByUrls.TryGetValue(url, out var file))
{
review.Images.Add(ConvertToReviewImage(file));

file.OwnerEntityId = review.Id;
file.OwnerEntityType = nameof(CustomerReview);
files.Add(file);
}
}

if (files.Count > 0)
{
await _fileUploadService.SaveChangesAsync(files);
}
return files;
}

protected virtual async Task<IList<File>> GetFiles(IEnumerable<string> urls)
Expand Down

0 comments on commit 45cfa14

Please sign in to comment.