Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/ToxiCode.BuyIt.Logistics.Api.Dtos/OrderDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ public class ItemInOrder
{
public long ItemId { get; set; }
public int Count { get; set; }
}

}
7 changes: 0 additions & 7 deletions src/ToxiCode.BuyIt.Logistics.Api.Dtos/Place.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task<CreateOrderResponse> Handle(CreateOrderCommand request, Cancel
{
OrderId = orderId
};
await _notificator.NotifyStatusChanged(orderId, OrderStatus.Created, cancellationToken);
// await _notificator.NotifyStatusChanged(orderId, OrderStatus.Created, cancellationToken);
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using MediatR;

namespace ToxiCode.BuyIt.Logistics.Api.BusinessLayer.Commands.GetOrders.Contracts;

public class GetOrderByIdCommand : IRequest<GetOrderByIdResponse>
{
public long OrderId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Dtos;

namespace ToxiCode.BuyIt.Logistics.Api.BusinessLayer.Commands.GetOrders.Contracts;

public class GetOrderByIdResponse
{
public OrderDto Orders { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -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<GetOrderByIdCommand, GetOrderByIdResponse>
{
private readonly OrdersRepository _ordersRepository;
private readonly ItemsRepository _itemsRepository;

public GetOrderByIdHandler(OrdersRepository ordersRepository, ItemsRepository itemsRepository)
{
_ordersRepository = ordersRepository;
_itemsRepository = itemsRepository;
}

public async Task<GetOrderByIdResponse> 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,
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ToxiCode.BuyIt.Logistics.Api.DataLayer.Repository.Items.Queries;

public class GetItemsByIdsQuery
{
public IEnumerable<long> Ids { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ToxiCode.BuyIt.Logistics.Api.DataLayer.Repository.Orders.Queries;

public class GetOrderByIdQuery
{
public long OrderId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/ToxiCode.BuyIt.Logistics.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
builder.ConfigurePorts();
var services = builder.Services;

services.AddControllers();
services.AddEndpointsApiExplorer();
services.AddDatabaseInfrastructure(builder.Configuration);
services.AddControllers();
Expand Down