Услуги
This commit is contained in:
@@ -21,8 +21,8 @@ public static class CatalogEndpoints
|
||||
|
||||
catalogGroup.MapPost("/categories", async ([FromBody] CreateCategoryCommand command, ISender sender) =>
|
||||
{
|
||||
var id = await sender.Send(command);
|
||||
return Results.Ok(id);
|
||||
var result = await sender.Send(command);
|
||||
return result.IsSuccess ? Results.Ok(result.Value) : Results.BadRequest(result.Error);
|
||||
})
|
||||
.WithName("CreateCategory")
|
||||
.WithOpenApi(operation => new(operation) { Summary = "Создать категорию (Admin)", Description = "Создает новую категорию. Требуются права администратора." });
|
||||
@@ -30,17 +30,27 @@ public static class CatalogEndpoints
|
||||
catalogGroup.MapGet("/categories", async (ISender sender) =>
|
||||
{
|
||||
var result = await sender.Send(new GetCategoriesQuery());
|
||||
return Results.Ok(result);
|
||||
return result.IsSuccess ? Results.Ok(result.Value) : Results.BadRequest(result.Error);
|
||||
})
|
||||
.WithName("GetCategories")
|
||||
.WithOpenApi(operation => new(operation) { Summary = "Получить все категории", Description = "Возвращает плоский список категорий с указанием ParentId для иерархии." });
|
||||
|
||||
// --- Услуги (Offers) ---
|
||||
|
||||
catalogGroup.MapPost("/offers", async ([FromBody] CreateOfferCommand command, ISender sender) =>
|
||||
var protectedOffersGroup = catalogGroup.MapGroup("").RequireAuthorization();
|
||||
|
||||
protectedOffersGroup.MapGet("/offers/my", async (ISender sender) =>
|
||||
{
|
||||
var id = await sender.Send(command);
|
||||
return Results.Ok(id);
|
||||
var result = await sender.Send(new GetMyOffersQuery());
|
||||
return result.IsSuccess ? Results.Ok(result.Value) : Results.BadRequest(result.Error);
|
||||
})
|
||||
.WithName("GetMyOffers")
|
||||
.WithOpenApi(operation => new(operation) { Summary = "Получить мои услуги", Description = "Возвращает список услуг текущего пользователя." });
|
||||
|
||||
protectedOffersGroup.MapPost("/offers", async ([FromBody] CreateOfferCommand command, ISender sender) =>
|
||||
{
|
||||
var result = await sender.Send(command);
|
||||
return result.IsSuccess ? Results.Ok(result.Value) : Results.BadRequest(result.Error);
|
||||
})
|
||||
.WithName("CreateOffer")
|
||||
.WithOpenApi(operation => new(operation) { Summary = "Создать оффер/услугу", Description = "Создает новое предложение услуги в указанной категории." });
|
||||
@@ -48,7 +58,7 @@ public static class CatalogEndpoints
|
||||
catalogGroup.MapGet("/offers/{id:guid}", async (Guid id, ISender sender) =>
|
||||
{
|
||||
var result = await sender.Send(new GetOfferByIdQuery(id));
|
||||
return result is not null ? Results.Ok(result) : Results.NotFound();
|
||||
return result.IsSuccess && result.Value is not null ? Results.Ok(result.Value) : Results.NotFound();
|
||||
})
|
||||
.WithName("GetOfferById")
|
||||
.WithOpenApi(operation => new(operation) { Summary = "Получить детали услуги по ID", Description = "Возвращает полную информацию об услуге." });
|
||||
|
||||
Reference in New Issue
Block a user