Skip to content

Commit

Permalink
Update namespace for DomainOperations.Products
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladyslav Horbachov committed Jul 22, 2023
1 parent 6308226 commit 63dfe2f
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 31 deletions.

This file was deleted.

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;
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);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FluentValidation;

namespace Inventory.Application.DomainOperations.Product.DeleteProducts;
namespace Inventory.Application.DomainOperations.Products.DeleteProducts;

internal sealed class DeleteProductsCommandValidator : AbstractValidator<DeleteProductsCommand>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
using BuildingBlocks.Application.CQRS.Queries;
using Inventory.Application.Models;

namespace Inventory.Application.DomainOperations.Product.GetProductById;
namespace Inventory.Application.DomainOperations.Products.GetProductById;

internal sealed record GetProductByIdQuery(Guid ProductId) : QueryBase<ProductModel?>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Inventory.Application.Models;
using Inventory.Domain.Products;

namespace Inventory.Application.DomainOperations.Product.GetProductById;
namespace Inventory.Application.DomainOperations.Products.GetProductById;

internal sealed class GetProductByIdQueryHandler : IQueryHandler<GetProductByIdQuery, ProductModel?>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FluentValidation;

namespace Inventory.Application.DomainOperations.Product.GetProductById;
namespace Inventory.Application.DomainOperations.Products.GetProductById;

internal sealed class GetProductByIdQueryValidator : AbstractValidator<GetProductByIdQuery>
{
Expand Down
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>;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Inventory.Domain.Products;
using MediatR;

namespace Inventory.Application.DomainOperations.Product.GetProducts;
namespace Inventory.Application.DomainOperations.Products.GetProducts;

internal sealed class GetProductsStreamQueryHandler : IStreamRequestHandler<GetProductsStreamQuery, ProductModel>
{
Expand Down
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;
}
}

0 comments on commit 63dfe2f

Please sign in to comment.