| | | 1 | | using System.ComponentModel.DataAnnotations; |
| | | 2 | | using ClutterStock.Domain.Abstractions; |
| | | 3 | | using Microsoft.AspNetCore.Http; |
| | | 4 | | using Microsoft.AspNetCore.Http.HttpResults; |
| | | 5 | | using Microsoft.AspNetCore.Mvc; |
| | | 6 | | |
| | | 7 | | namespace ClutterStock.Domain.Features.Items.DeleteItem; |
| | | 8 | | |
| | | 9 | | [HttpMethod(HttpVerb.Delete)] |
| | | 10 | | [OpenApiDescription("Deletes an item by id.")] |
| | | 11 | | public class DeleteItemEndpoint : IEndpoint |
| | | 12 | | { |
| | 3 | 13 | | public static string Route => "/items/{id}"; |
| | | 14 | | |
| | 3 | 15 | | public static Delegate Handler => (Func<int, IDeleteItemCommandHandler, CancellationToken, Task<Results<NoContent, N |
| | | 16 | | |
| | | 17 | | private static async Task<Results<NoContent, NotFound>> Handle([FromRoute, Range(1, int.MaxValue)] int id, |
| | | 18 | | IDeleteItemCommandHandler handler, |
| | | 19 | | CancellationToken cancellationToken) |
| | | 20 | | { |
| | 2 | 21 | | var deleted = await handler.HandleAsync(new IDeleteItemCommandHandler.Command(id), cancellationToken); |
| | 2 | 22 | | return deleted ? TypedResults.NoContent() : TypedResults.NotFound(); |
| | 2 | 23 | | } |
| | | 24 | | } |