| | | 1 | | using ClutterStock.Contracts.Items; |
| | | 2 | | using ClutterStock.Domain.Abstractions; |
| | | 3 | | using ClutterStock.Domain.Extensions; |
| | | 4 | | using Microsoft.AspNetCore.Http; |
| | | 5 | | using Microsoft.AspNetCore.Http.HttpResults; |
| | | 6 | | using Microsoft.AspNetCore.Mvc; |
| | | 7 | | |
| | | 8 | | namespace ClutterStock.Domain.Features.Items.AddItem; |
| | | 9 | | |
| | | 10 | | [HttpMethod(HttpVerb.Post)] |
| | | 11 | | [OpenApiDescription("Creates a new item.")] |
| | | 12 | | public class AddItemEndpoint : IEndpoint |
| | | 13 | | { |
| | 3 | 14 | | public static string Route => "/items"; |
| | | 15 | | |
| | 3 | 16 | | public static Delegate Handler => (Func<AddItemRequest, IAddItemCommandHandler, CancellationToken, Task<Created<Item |
| | | 17 | | |
| | | 18 | | private static async Task<Created<ItemResponse>> Handle([FromBody] AddItemRequest request, |
| | | 19 | | IAddItemCommandHandler handler, |
| | | 20 | | CancellationToken cancellationToken) |
| | | 21 | | { |
| | 4 | 22 | | var command = new IAddItemCommandHandler.Command(request.RoomId, request.Name, request.Description, request.Cate |
| | 4 | 23 | | var item = await handler.HandleAsync(command, cancellationToken); |
| | 4 | 24 | | return TypedResults.Created($"{ApiRoutePrefix.V1}/items/{item.Id}", item.ToResponse()); |
| | 4 | 25 | | } |
| | | 26 | | } |