| | | 1 | | using ClutterStock.Contracts.Locations; |
| | | 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.Locations.AddLocation; |
| | | 9 | | |
| | | 10 | | [HttpMethod(HttpVerb.Post)] |
| | | 11 | | [OpenApiDescription("Creates a new location.")] |
| | | 12 | | public class AddLocationEndpoint : IEndpoint |
| | | 13 | | { |
| | 3 | 14 | | public static string Route => "/locations"; |
| | | 15 | | |
| | 3 | 16 | | public static Delegate Handler => (Func<AddLocationRequest, IAddLocationCommandHandler, CancellationToken, Task<Crea |
| | | 17 | | |
| | | 18 | | private static async Task<Created<LocationResponse>> Handle([FromBody] AddLocationRequest request, |
| | | 19 | | IAddLocationCommandHandler handler, |
| | | 20 | | CancellationToken cancellationToken) |
| | | 21 | | { |
| | 4 | 22 | | var command = new IAddLocationCommandHandler.Command(request.Name, request.Description); |
| | 4 | 23 | | var location = await handler.HandleAsync(command, cancellationToken); |
| | 4 | 24 | | return TypedResults.Created($"/locations/{location.Id}", location.ToResponse()); |
| | 4 | 25 | | } |
| | | 26 | | } |