From d382945b3bbb4f2486a316aa5db8620c0c8a8cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=ABl=20Mugnier?= Date: Thu, 10 Jun 2021 20:45:22 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20-=20Ajout=20d'une=20image=20par=20d=C3=A9?= =?UTF-8?q?faut=20sur=20un=20produit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Interfaces/Infrastructure/IPictureService.cs | 3 +++ Sheaft.Infrastructure/Services/PictureService.cs | 2 +- Sheaft.Mediatr/Product/Commands/CreateProductCommand.cs | 5 +++++ Sheaft.Mediatr/Product/Commands/UpdateProductCommand.cs | 7 ++++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Sheaft.Application/Interfaces/Infrastructure/IPictureService.cs b/Sheaft.Application/Interfaces/Infrastructure/IPictureService.cs index 0431a25ec..595eaec71 100644 --- a/Sheaft.Application/Interfaces/Infrastructure/IPictureService.cs +++ b/Sheaft.Application/Interfaces/Infrastructure/IPictureService.cs @@ -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 { @@ -12,5 +14,6 @@ public interface IPictureService Task> HandleProductPictureAsync(Domain.Product product, Guid pictureId, string picture, CancellationToken token); Task> HandleTagPictureAsync(Domain.Tag tag, string picture, CancellationToken token); Task> HandleTagIconAsync(Domain.Tag tag, string icon, CancellationToken token); + string GetDefaultProductPicture(IEnumerable tags); } } \ No newline at end of file diff --git a/Sheaft.Infrastructure/Services/PictureService.cs b/Sheaft.Infrastructure/Services/PictureService.cs index 2850bb42f..d1d3b7322 100644 --- a/Sheaft.Infrastructure/Services/PictureService.cs +++ b/Sheaft.Infrastructure/Services/PictureService.cs @@ -132,7 +132,7 @@ await UploadProductPreviewAsync(image, entity.ProducerId, entity.Id, pictureId, } } - private string GetDefaultProductPicture(IEnumerable tags) + public string GetDefaultProductPicture(IEnumerable tags) { var category = tags.FirstOrDefault(t => t.Kind == TagKind.Category); return category?.Picture; diff --git a/Sheaft.Mediatr/Product/Commands/CreateProductCommand.cs b/Sheaft.Mediatr/Product/Commands/CreateProductCommand.cs index f653d2e1e..b4e73abd0 100644 --- a/Sheaft.Mediatr/Product/Commands/CreateProductCommand.cs +++ b/Sheaft.Mediatr/Product/Commands/CreateProductCommand.cs @@ -152,6 +152,11 @@ await _context.Products.AnyAsync( 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); diff --git a/Sheaft.Mediatr/Product/Commands/UpdateProductCommand.cs b/Sheaft.Mediatr/Product/Commands/UpdateProductCommand.cs index 6abcd509d..f96679067 100644 --- a/Sheaft.Mediatr/Product/Commands/UpdateProductCommand.cs +++ b/Sheaft.Mediatr/Product/Commands/UpdateProductCommand.cs @@ -161,7 +161,12 @@ public async Task 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);