-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update namespace for DomainOperations.Products
- Loading branch information
Vladyslav Horbachov
committed
Jul 22, 2023
1 parent
6308226
commit 63dfe2f
Showing
10 changed files
with
69 additions
and
31 deletions.
There are no files selected for viewing
24 changes: 0 additions & 24 deletions
24
...ntory.Application/DomainOperations/Product/DeleteProducts/DeleteProductsCommandHandler.cs
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...t/DeleteProducts/DeleteProductsCommand.cs → ...s/DeleteProducts/DeleteProductsCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
using BuildingBlocks.Application.CQRS.Commands; | ||
using Inventory.Application.Models; | ||
|
||
namespace Inventory.Application.DomainOperations.Product.DeleteProducts; | ||
namespace Inventory.Application.DomainOperations.Products.DeleteProducts; | ||
|
||
internal sealed record DeleteProductsCommand(ProductModel[] Products) : CommandBase; |
43 changes: 43 additions & 0 deletions
43
...tory.Application/DomainOperations/Products/DeleteProducts/DeleteProductsCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using BuildingBlocks.Application.CQRS.Commands; | ||
using Inventory.Domain.Orders; | ||
using Inventory.Domain.Products; | ||
using Inventory.Domain.Warehouses; | ||
using Inventory.Persistence.Database.Repositories; | ||
|
||
namespace Inventory.Application.DomainOperations.Products.DeleteProducts; | ||
|
||
internal sealed class DeleteProductsCommandHandler : ICommandHandler<DeleteProductsCommand> | ||
{ | ||
private readonly IProductsRepository _productsRepository; | ||
private readonly IOrdersRepository _ordersRepository; | ||
private readonly IWarehouseRepository _warehouseRepository; | ||
|
||
public DeleteProductsCommandHandler(IProductsRepository productsRepository, IOrdersRepository ordersRepository, IWarehouseRepository warehouseRepository) | ||
{ | ||
_productsRepository = productsRepository; | ||
_ordersRepository = ordersRepository; | ||
_warehouseRepository = warehouseRepository; | ||
} | ||
|
||
public async Task Handle(DeleteProductsCommand request, CancellationToken cancellationToken) | ||
{ | ||
var productIds = request.Products.Select(productModel => new ProductId(productModel.Id)).ToArray(); | ||
|
||
var usedProducts = await _ordersRepository.GetListOfUsedProducts(productIds, cancellationToken); | ||
var warehouses = await _warehouseRepository.GetManyByIdsAsync(usedProducts, cancellationToken); | ||
foreach (var warehouse in warehouses) | ||
{ | ||
warehouse.DeactivateProduct(); | ||
} | ||
|
||
var unusedProducts = productIds.Except(usedProducts); | ||
foreach (var productId in unusedProducts) | ||
{ | ||
await _productsRepository.DeleteByIdAsync(productId, cancellationToken); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...roducts/DeleteProductsCommandValidator.cs → ...roducts/DeleteProductsCommandValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...oductById/GetProductByIdQueryValidator.cs → ...oductById/GetProductByIdQueryValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...uct/GetProducts/GetProductsStreamQuery.cs → ...cts/GetProducts/GetProductsStreamQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
using Inventory.Application.Models; | ||
using MediatR; | ||
|
||
namespace Inventory.Application.DomainOperations.Product.GetProducts; | ||
namespace Inventory.Application.DomainOperations.Products.GetProducts; | ||
|
||
internal sealed record GetProductsStreamQuery : IStreamRequest<ProductModel>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ion/DomainOperations/Products/ProductDeactivated/ProductDeactivatedNotificationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Inventory.Domain.Warehouses.Events; | ||
using MediatR; | ||
|
||
namespace Inventory.Application.DomainOperations.Products.ProductDeactivated; | ||
|
||
internal sealed class ProductDeactivatedNotificationHandler : INotificationHandler<ProductDeactivatedEvent> | ||
{ | ||
public Task Handle(ProductDeactivatedEvent @event, CancellationToken cancellationToken) | ||
{ | ||
if (@event.RemainingProductsQuantity > 0) | ||
{ | ||
// Handle remaining products management in warehouse. | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
} |