| | | 1 | | using System.ComponentModel.DataAnnotations; |
| | | 2 | | using ClutterStock.Contracts.Items; |
| | | 3 | | using ClutterStock.Domain.Abstractions; |
| | | 4 | | using ClutterStock.Domain.Extensions; |
| | | 5 | | using Microsoft.AspNetCore.Http; |
| | | 6 | | using Microsoft.AspNetCore.Http.HttpResults; |
| | | 7 | | using Microsoft.AspNetCore.Mvc; |
| | | 8 | | |
| | | 9 | | namespace ClutterStock.Domain.Features.Items.GetItem; |
| | | 10 | | |
| | | 11 | | [HttpMethod(HttpVerb.Get)] |
| | | 12 | | [OpenApiDescription("Returns a single item by id.")] |
| | | 13 | | public class GetItemEndpoint : IEndpoint |
| | | 14 | | { |
| | 3 | 15 | | public static string Route => "/items/{id}"; |
| | | 16 | | |
| | 3 | 17 | | public static Delegate Handler => (Func<int, IGetItemQueryHandler, CancellationToken, Task<Results<Ok<ItemResponse>, |
| | | 18 | | |
| | | 19 | | private static async Task<Results<Ok<ItemResponse>, NotFound>> Handle([FromRoute, Range(1, int.MaxValue)] int id, |
| | | 20 | | IGetItemQueryHandler handler, |
| | | 21 | | CancellationToken cancellationToken) |
| | | 22 | | { |
| | 2 | 23 | | var item = await handler.HandleAsync(new IGetItemQueryHandler.Query(id), cancellationToken); |
| | 2 | 24 | | return item is null ? TypedResults.NotFound() : TypedResults.Ok(item.ToResponse()); |
| | 2 | 25 | | } |
| | | 26 | | } |