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