diff --git a/src/ToxiCode.BuyIt.Logistics.Api.Dtos/OrderDto.cs b/src/ToxiCode.BuyIt.Logistics.Api.Dtos/OrderDto.cs index efe70a1..b077eb1 100644 --- a/src/ToxiCode.BuyIt.Logistics.Api.Dtos/OrderDto.cs +++ b/src/ToxiCode.BuyIt.Logistics.Api.Dtos/OrderDto.cs @@ -17,5 +17,4 @@ public class ItemInOrder { public long ItemId { get; set; } public int Count { get; set; } -} - +} \ No newline at end of file diff --git a/src/ToxiCode.BuyIt.Logistics.Api.Dtos/Place.cs b/src/ToxiCode.BuyIt.Logistics.Api.Dtos/Place.cs deleted file mode 100644 index aacb1b5..0000000 --- a/src/ToxiCode.BuyIt.Logistics.Api.Dtos/Place.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Dtos; - -public class Place -{ - public long Id { get; set; } - public string Address { get; set; } = null!; -} \ No newline at end of file diff --git a/src/ToxiCode.BuyIt.Logistics.Api/BusinessLayer/Commands/CreateOrder/CreateOrderHandler.cs b/src/ToxiCode.BuyIt.Logistics.Api/BusinessLayer/Commands/CreateOrder/CreateOrderHandler.cs index 3779d9e..c0fda3a 100644 --- a/src/ToxiCode.BuyIt.Logistics.Api/BusinessLayer/Commands/CreateOrder/CreateOrderHandler.cs +++ b/src/ToxiCode.BuyIt.Logistics.Api/BusinessLayer/Commands/CreateOrder/CreateOrderHandler.cs @@ -50,7 +50,7 @@ public async Task Handle(CreateOrderCommand request, Cancel { OrderId = orderId }; - await _notificator.NotifyStatusChanged(orderId, OrderStatus.Created, cancellationToken); + // await _notificator.NotifyStatusChanged(orderId, OrderStatus.Created, cancellationToken); return result; } } \ No newline at end of file diff --git a/src/ToxiCode.BuyIt.Logistics.Api/BusinessLayer/Commands/GetOrders/Contracts/GetOrderByIdCommand.cs b/src/ToxiCode.BuyIt.Logistics.Api/BusinessLayer/Commands/GetOrders/Contracts/GetOrderByIdCommand.cs new file mode 100644 index 0000000..6ad9d2f --- /dev/null +++ b/src/ToxiCode.BuyIt.Logistics.Api/BusinessLayer/Commands/GetOrders/Contracts/GetOrderByIdCommand.cs @@ -0,0 +1,8 @@ +using MediatR; + +namespace ToxiCode.BuyIt.Logistics.Api.BusinessLayer.Commands.GetOrders.Contracts; + +public class GetOrderByIdCommand : IRequest +{ + public long OrderId { get; set; } +} \ No newline at end of file diff --git a/src/ToxiCode.BuyIt.Logistics.Api/BusinessLayer/Commands/GetOrders/Contracts/GetOrderByIdResponse.cs b/src/ToxiCode.BuyIt.Logistics.Api/BusinessLayer/Commands/GetOrders/Contracts/GetOrderByIdResponse.cs new file mode 100644 index 0000000..0eff02d --- /dev/null +++ b/src/ToxiCode.BuyIt.Logistics.Api/BusinessLayer/Commands/GetOrders/Contracts/GetOrderByIdResponse.cs @@ -0,0 +1,8 @@ +using Dtos; + +namespace ToxiCode.BuyIt.Logistics.Api.BusinessLayer.Commands.GetOrders.Contracts; + +public class GetOrderByIdResponse +{ + public OrderDto Orders { get; set; } = null!; +} \ No newline at end of file diff --git a/src/ToxiCode.BuyIt.Logistics.Api/BusinessLayer/Commands/GetOrders/GetOrderByIdHandler.cs b/src/ToxiCode.BuyIt.Logistics.Api/BusinessLayer/Commands/GetOrders/GetOrderByIdHandler.cs new file mode 100644 index 0000000..f184589 --- /dev/null +++ b/src/ToxiCode.BuyIt.Logistics.Api/BusinessLayer/Commands/GetOrders/GetOrderByIdHandler.cs @@ -0,0 +1,51 @@ +using Dtos; +using MediatR; +using ToxiCode.BuyIt.Logistics.Api.BusinessLayer.Commands.GetItems.Contracts; +using ToxiCode.BuyIt.Logistics.Api.BusinessLayer.Commands.GetOrders.Contracts; +using ToxiCode.BuyIt.Logistics.Api.DataLayer.Repository.Items; +using ToxiCode.BuyIt.Logistics.Api.DataLayer.Repository.Items.Queries; +using ToxiCode.BuyIt.Logistics.Api.DataLayer.Repository.Orders; +using ToxiCode.BuyIt.Logistics.Api.DataLayer.Repository.Orders.Queries; + +namespace ToxiCode.BuyIt.Logistics.Api.BusinessLayer.Commands.GetOrders; + +public class GetOrderByIdHandler : IRequestHandler +{ + private readonly OrdersRepository _ordersRepository; + private readonly ItemsRepository _itemsRepository; + + public GetOrderByIdHandler(OrdersRepository ordersRepository, ItemsRepository itemsRepository) + { + _ordersRepository = ordersRepository; + _itemsRepository = itemsRepository; + } + + public async Task Handle(GetOrderByIdCommand request, CancellationToken cancellationToken) + { + var query = new GetOrderByIdQuery + { + OrderId = request.OrderId + }; + var order = await _ordersRepository.GetOrderById(query.OrderId); + + if (order == null) + return new GetOrderByIdResponse(); + + order.Items = await _itemsRepository.GetItemsByOrderId(order.Id, cancellationToken); + + + return new GetOrderByIdResponse + { + Orders = new OrderDto + { + From = order!.From, + To = order.To, + Items = order.Items, + Id = order.Id, + Status = order.Status, + BuyerId = order.BuyerId, + CreationDate = order.CreationDate, + } + }; + } +} \ No newline at end of file diff --git a/src/ToxiCode.BuyIt.Logistics.Api/DataLayer/Repository/Items/Queries/GetItemsByIdsQuery.cs b/src/ToxiCode.BuyIt.Logistics.Api/DataLayer/Repository/Items/Queries/GetItemsByIdsQuery.cs new file mode 100644 index 0000000..d903c8a --- /dev/null +++ b/src/ToxiCode.BuyIt.Logistics.Api/DataLayer/Repository/Items/Queries/GetItemsByIdsQuery.cs @@ -0,0 +1,6 @@ +namespace ToxiCode.BuyIt.Logistics.Api.DataLayer.Repository.Items.Queries; + +public class GetItemsByIdsQuery +{ + public IEnumerable Ids { get; set; } = null!; +} \ No newline at end of file diff --git a/src/ToxiCode.BuyIt.Logistics.Api/DataLayer/Repository/Orders/Queries/GetOrderByIdQuery.cs b/src/ToxiCode.BuyIt.Logistics.Api/DataLayer/Repository/Orders/Queries/GetOrderByIdQuery.cs new file mode 100644 index 0000000..dca3966 --- /dev/null +++ b/src/ToxiCode.BuyIt.Logistics.Api/DataLayer/Repository/Orders/Queries/GetOrderByIdQuery.cs @@ -0,0 +1,6 @@ +namespace ToxiCode.BuyIt.Logistics.Api.DataLayer.Repository.Orders.Queries; + +public class GetOrderByIdQuery +{ + public long OrderId { get; set; } +} \ No newline at end of file diff --git a/src/ToxiCode.BuyIt.Logistics.Api/HttpControllers/OrderController.cs b/src/ToxiCode.BuyIt.Logistics.Api/HttpControllers/OrderController.cs index 0e0807d..b99d42c 100644 --- a/src/ToxiCode.BuyIt.Logistics.Api/HttpControllers/OrderController.cs +++ b/src/ToxiCode.BuyIt.Logistics.Api/HttpControllers/OrderController.cs @@ -1,9 +1,6 @@ using Dtos; -using JetBrains.Annotations; using MediatR; using Microsoft.AspNetCore.Mvc; -using ToxiCode.BuyIt.Logistics.Api.BusinessLayer.Commands; -using ToxiCode.BuyIt.Logistics.Api.BusinessLayer.Commands.ChangeOrderById.Contracts; using ToxiCode.BuyIt.Logistics.Api.BusinessLayer.Commands.CreateOrder.Contracts; using ToxiCode.BuyIt.Logistics.Api.BusinessLayer.Commands.GetOrders.Contracts; diff --git a/src/ToxiCode.BuyIt.Logistics.Api/Program.cs b/src/ToxiCode.BuyIt.Logistics.Api/Program.cs index dc8c117..d537c5c 100644 --- a/src/ToxiCode.BuyIt.Logistics.Api/Program.cs +++ b/src/ToxiCode.BuyIt.Logistics.Api/Program.cs @@ -14,6 +14,7 @@ builder.ConfigurePorts(); var services = builder.Services; +services.AddControllers(); services.AddEndpointsApiExplorer(); services.AddDatabaseInfrastructure(builder.Configuration); services.AddControllers();