Модуль заказов
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Nashel.Modules.Order.Application.Commands;
|
||||
using Nashel.Modules.Order.Domain.Enums;
|
||||
|
||||
namespace Nashel.Modules.Order.Presentation;
|
||||
|
||||
public static class OrderEndpoints
|
||||
{
|
||||
public static void MapOrderEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/api/orders").WithTags("Orders");
|
||||
|
||||
group.MapPost("/", async (CreateOrderRequest request, ISender sender) =>
|
||||
{
|
||||
var command = new CreateOrderCommand(
|
||||
request.CustomerId,
|
||||
request.ServiceId,
|
||||
request.Type,
|
||||
request.Address,
|
||||
request.Latitude,
|
||||
request.Longitude,
|
||||
request.Deadline,
|
||||
request.PerformerId
|
||||
);
|
||||
var orderId = await sender.Send(command);
|
||||
return Results.Ok(orderId);
|
||||
})
|
||||
.WithName("CreateOrder")
|
||||
.WithOpenApi(operation => new(operation) { Summary = "Создание нового заказа.", Description = "Создает прямой или публичный заказ." });
|
||||
|
||||
group.MapPost("/{id:guid}/applications", async (Guid id, AddApplicationRequest request, ISender sender) =>
|
||||
{
|
||||
var command = new AddApplicationCommand(
|
||||
id,
|
||||
request.PerformerId,
|
||||
request.Amount,
|
||||
request.Currency,
|
||||
request.Comment
|
||||
);
|
||||
await sender.Send(command);
|
||||
return Results.Ok();
|
||||
})
|
||||
.WithName("AddOrderApplication")
|
||||
.WithOpenApi(operation => new(operation) { Summary = "Добавление отклика на заказ." });
|
||||
|
||||
group.MapPost("/{id:guid}/select-performer", async (Guid id, SelectPerformerRequest request, ISender sender) =>
|
||||
{
|
||||
var command = new SelectPerformerCommand(id, request.PerformerId);
|
||||
await sender.Send(command);
|
||||
return Results.Ok();
|
||||
})
|
||||
.WithName("SelectPerformer")
|
||||
.WithOpenApi(operation => new(operation) { Summary = "Выбор исполнителя для заказа." });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Запрос на создание заказа.
|
||||
/// </summary>
|
||||
public record CreateOrderRequest(
|
||||
Guid CustomerId,
|
||||
Guid ServiceId,
|
||||
OrderType Type,
|
||||
string Address,
|
||||
double Latitude,
|
||||
double Longitude,
|
||||
DateTime? Deadline,
|
||||
Guid? PerformerId
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Запрос на добавление отклика.
|
||||
/// </summary>
|
||||
public record AddApplicationRequest(
|
||||
Guid PerformerId,
|
||||
decimal Amount,
|
||||
string Currency,
|
||||
string Comment
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Запрос на выбор исполнителя.
|
||||
/// </summary>
|
||||
public record SelectPerformerRequest(Guid PerformerId);
|
||||
Reference in New Issue
Block a user