Skip to content

Commit

Permalink
🗑️ Drop OpenAPI convenience extensions (#36)
Browse files Browse the repository at this point in the history
Closes #28
  • Loading branch information
Hona authored Mar 20, 2024
1 parent 2e179ff commit 228f4c4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 91 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,67 @@ public static void MapEndpoints(IEndpointRouteBuilder endpoints)
var group = endpoints.MapGroup("/todos")
.WithTags(nameof(Todo));

group.MapPostWithOpenApi(string.Empty,
async (CreateTodoCommand command, ISender sender, CancellationToken cancellationToken) =>
{
var id = await sender.Send(command, cancellationToken);
return Results.Created($"/todos/{id}", id);
});

group.MapPutWithOpenApi("/{id:guid}",
group.MapPost("",
async (CreateTodoCommand command, ISender sender, CancellationToken cancellationToken) =>
{
var id = await sender.Send(command, cancellationToken);
return Results.Created($"/todos/{id}", id);
})
.Produces<Todo>(StatusCodes.Status201Created)
.ProducesValidationProblem()
.ProducesProblem(StatusCodes.Status500InternalServerError)
.WithTags(nameof(Todo));

group.MapPut("/{id:guid}",
async (Guid id, UpdateTodoCommand command, ISender sender, CancellationToken cancellationToken) =>
{
await sender.Send(command with { Id = id }, cancellationToken);
return Results.NoContent();
})
.Produces(StatusCodes.Status204NoContent)
.Produces(StatusCodes.Status404NotFound)
.ProducesValidationProblem()
.ProducesProblem(StatusCodes.Status500InternalServerError)
.WithTags(nameof(Todo));

group.MapPutWithOpenApi("/{id:guid}/complete",
group.MapPut("/{id:guid}/complete",
async (Guid id, ISender sender, CancellationToken cancellationToken) =>
{
await sender.Send(new CompleteTodoCommand(id), cancellationToken);
return Results.NoContent();
})
.Produces(StatusCodes.Status204NoContent)
.Produces(StatusCodes.Status404NotFound)
.ProducesValidationProblem()
.ProducesProblem(StatusCodes.Status500InternalServerError)
.WithTags(nameof(Todo));

group.MapDeleteWithOpenApi("/{id:guid}",
async (Guid id, ISender sender, CancellationToken cancellationToken) =>
{
await sender.Send(new DeleteTodoCommand(id), cancellationToken);
return Results.NoContent();
});
group.MapDelete("/{id:guid}",
async (Guid id, ISender sender, CancellationToken cancellationToken) =>
{
await sender.Send(new DeleteTodoCommand(id), cancellationToken);
return Results.NoContent();
})
.Produces(StatusCodes.Status204NoContent)
.Produces(StatusCodes.Status404NotFound)
.ProducesValidationProblem()
.ProducesProblem(StatusCodes.Status500InternalServerError)
.WithTags(nameof(Todo));

group.MapGetWithOpenApi<Todo>("/{id:guid}",
(Guid id, ISender sender, CancellationToken cancellationToken)
=> sender.Send(new GetTodoQuery(id), cancellationToken));
group.MapGet("/{id:guid}",
(Guid id, ISender sender, CancellationToken cancellationToken)
=> sender.Send(new GetTodoQuery(id), cancellationToken))
.Produces<Todo>()
.Produces(StatusCodes.Status404NotFound)
.ProducesProblem(StatusCodes.Status500InternalServerError)
.WithTags(nameof(Todo));

group.MapGetWithOpenApi<IImmutableList<Todo>>(string.Empty,
(bool? isCompleted, ISender sender, CancellationToken cancellationToken)
=> sender.Send(new GetAllTodosQuery(isCompleted), cancellationToken));
group.MapGet("",
(bool? isCompleted, ISender sender, CancellationToken cancellationToken)
=> sender.Send(new GetAllTodosQuery(isCompleted), cancellationToken))
.Produces<IImmutableList<Todo>>()
.Produces(StatusCodes.Status404NotFound)
.ProducesProblem(StatusCodes.Status500InternalServerError)
.WithTags(nameof(Todo));
}
}

0 comments on commit 228f4c4

Please sign in to comment.