Skip to content

Commit

Permalink
Fix - Ajout d'une image par défaut sur un produit
Browse files Browse the repository at this point in the history
  • Loading branch information
noelmugnier committed Jun 10, 2021
1 parent b9a3dc4 commit d382945
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Sheaft.Core;
using Sheaft.Domain;

namespace Sheaft.Application.Interfaces.Infrastructure
{
Expand All @@ -12,5 +14,6 @@ public interface IPictureService
Task<Result<string>> HandleProductPictureAsync(Domain.Product product, Guid pictureId, string picture, CancellationToken token);
Task<Result<string>> HandleTagPictureAsync(Domain.Tag tag, string picture, CancellationToken token);
Task<Result<string>> HandleTagIconAsync(Domain.Tag tag, string icon, CancellationToken token);
string GetDefaultProductPicture(IEnumerable<Tag> tags);
}
}
2 changes: 1 addition & 1 deletion Sheaft.Infrastructure/Services/PictureService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ await UploadProductPreviewAsync(image, entity.ProducerId, entity.Id, pictureId,
}
}

private string GetDefaultProductPicture(IEnumerable<Tag> tags)
public string GetDefaultProductPicture(IEnumerable<Tag> tags)
{
var category = tags.FirstOrDefault(t => t.Kind == TagKind.Category);
return category?.Picture;
Expand Down
5 changes: 5 additions & 0 deletions Sheaft.Mediatr/Product/Commands/CreateProductCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ await _context.Products.AnyAsync(
if (!result.Succeeded)
return Failure<Guid>(result);
}
else
{
var picture = _imageService.GetDefaultProductPicture(tags);
entity.AddPicture(new ProductPicture(Guid.NewGuid(), picture, 0));
}

await _context.SaveChangesAsync(token);
await transaction.CommitAsync(token);
Expand Down
7 changes: 6 additions & 1 deletion Sheaft.Mediatr/Product/Commands/UpdateProductCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ public async Task<Result> Handle(UpdateProductCommand request, CancellationToken
if (!result.Succeeded)
return Failure(result);
}

else
{
var picture = _imageService.GetDefaultProductPicture(tags);
entity.AddPicture(new ProductPicture(Guid.NewGuid(), picture, 0));
}

await _context.SaveChangesAsync(token);
await transaction.CommitAsync(token);

Expand Down

0 comments on commit d382945

Please sign in to comment.