| | | 1 | | using System.ComponentModel.DataAnnotations; |
| | | 2 | | using ClutterStock.Contracts.Locations; |
| | | 3 | | using ClutterStock.Domain.Abstractions; |
| | | 4 | | using Microsoft.AspNetCore.Http.HttpResults; |
| | | 5 | | using Microsoft.AspNetCore.Mvc; |
| | | 6 | | |
| | | 7 | | namespace ClutterStock.Domain.Features.Locations.UpdateLocation; |
| | | 8 | | |
| | | 9 | | [HttpMethod(HttpVerb.Put)] |
| | | 10 | | [OpenApiDescription("Updates an existing location by id.")] |
| | | 11 | | public class UpdateLocationEndpoint : IEndpoint |
| | | 12 | | { |
| | 3 | 13 | | public static string Route => "/locations/{id}"; |
| | | 14 | | |
| | 3 | 15 | | public static Delegate Handler => (Func<int, UpdateLocationRequest, IUpdateLocationCommandHandler, CancellationToken |
| | | 16 | | |
| | | 17 | | private static async Task<Results<Ok<LocationResponse>, NotFound>> Handle([FromRoute, Range(1, int.MaxValue)] int id |
| | | 18 | | [FromBody] UpdateLocationRequest request, |
| | | 19 | | IUpdateLocationCommandHandler handler, |
| | | 20 | | CancellationToken cancellationToken) |
| | | 21 | | { |
| | 2 | 22 | | var command = new IUpdateLocationCommandHandler.Command(id, request.Name, request.Description); |
| | 2 | 23 | | return await handler.HandleAsync(command, cancellationToken); |
| | 2 | 24 | | } |
| | | 25 | | } |