Skip to content

Commit

Permalink
New - Ne pas notifier les producteurs lors de l'import depuis le site…
Browse files Browse the repository at this point in the history
… de gestion pour ne pas les surcharger d'emails
  • Loading branch information
noelmugnier committed Nov 5, 2020
1 parent 491ef8f commit 729a802
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public ImportProductsCommand(RequestUser requestUser) : base(requestUser)
}

public Guid Id { get; set; }
public bool NotifyOnUpdates { get; set; } = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public QueueImportProductsCommand(RequestUser requestUser) : base(requestUser)
public Guid Id { get; set; }
public string FileName { get; set; }
public byte[] FileStream { get; set; }
public bool NotifyOnUpdates { get; set; } = true;
}
}
13 changes: 9 additions & 4 deletions Sheaft.Application.Handlers/Commands/ProductCommandsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public async Task<Result<Guid>> Handle(QueueImportProductsCommand request, Cance
await _context.AddAsync(entity, token);
await _context.SaveChangesAsync(token);
_mediatr.Post(new ImportProductsCommand(request.RequestUser) { Id = entity.Id });
_mediatr.Post(new ImportProductsCommand(request.RequestUser) { Id = entity.Id, NotifyOnUpdates = request.NotifyOnUpdates });
return Created(entity.Id);
});
}
Expand All @@ -280,7 +280,8 @@ public async Task<Result<bool>> Handle(ImportProductsCommand request, Cancellati
if (!startResult.Success)
throw startResult.Exception;
_mediatr.Post(new ProductImportProcessingEvent(request.RequestUser) { JobId = job.Id });
if(request.NotifyOnUpdates)
_mediatr.Post(new ProductImportProcessingEvent(request.RequestUser) { JobId = job.Id });
var data = await _blobService.DownloadImportProductsFileAsync(job.User.Id, job.Id, token);
if (!data.Success)
Expand Down Expand Up @@ -319,12 +320,16 @@ public async Task<Result<bool>> Handle(ImportProductsCommand request, Cancellati
if (!result.Success)
throw result.Exception;
_mediatr.Post(new ProductImportSucceededEvent(request.RequestUser) { JobId = job.Id });
if (request.NotifyOnUpdates)
_mediatr.Post(new ProductImportSucceededEvent(request.RequestUser) { JobId = job.Id });
return result;
}
catch (Exception e)
{
_mediatr.Post(new ProductImportFailedEvent(request.RequestUser) { JobId = job.Id });
if (request.NotifyOnUpdates)
_mediatr.Post(new ProductImportFailedEvent(request.RequestUser) { JobId = job.Id });
return await _mediatr.Process(new FailJobCommand(request.RequestUser) { Id = job.Id, Reason = e.Message }, token);
}
});
Expand Down
2 changes: 1 addition & 1 deletion Sheaft.Web.Manage/Controllers/ProductsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public async Task<IActionResult> Import(IEnumerable<IFormFile> products, Cancell
using (var stream = new MemoryStream())
{
await formFile.CopyToAsync(stream, token);
var result = await _mediatr.Process(new QueueImportProductsCommand(requestUser) { Id = requestUser.Id, FileName = formFile.FileName, FileStream = stream.ToArray() }, token);
var result = await _mediatr.Process(new QueueImportProductsCommand(requestUser) { Id = requestUser.Id, NotifyOnUpdates = false, FileName = formFile.FileName, FileStream = stream.ToArray() }, token);
if (!result.Success)
return BadRequest(result);
}
Expand Down

0 comments on commit 729a802

Please sign in to comment.