-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚗️ Experiment with grouping endpoints into a single file.
- Loading branch information
1 parent
eab4ce1
commit d88bff0
Showing
10 changed files
with
472 additions
and
486 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using CleanArchitecture.Application.TodoLists.Commands.CreateTodoList; | ||
using CleanArchitecture.Application.TodoLists.Commands.DeleteTodoList; | ||
using CleanArchitecture.Application.TodoLists.Commands.UpdateTodoList; | ||
using CleanArchitecture.Application.TodoLists.Queries.ExportTodos; | ||
using CleanArchitecture.Application.TodoLists.Queries.GetTodos; | ||
using CleanArchitecture.WebUI.Filters; | ||
|
||
namespace CleanArchitecture.WebUI.Endpoints; | ||
|
||
public class TodoListEndpoints | ||
{ | ||
private const string GroupName = "TodoLists"; | ||
|
||
public static void Map(WebApplication app) | ||
{ | ||
var group = app | ||
.MapGroup($"/api/{GroupName}") | ||
.WithTags(GroupName) | ||
.RequireAuthorization() | ||
.WithOpenApi() | ||
.AddEndpointFilter<ApiExceptionFilter>(); | ||
|
||
group | ||
.MapGet("/", async (ISender sender) => await sender.Send(new GetTodosQuery())) | ||
.WithName($"{GroupName}_GetTodoLists"); | ||
|
||
group | ||
.MapGet("/Export/{id}", | ||
async (ISender sender, int id) => | ||
{ | ||
var vm = await sender.Send(new ExportTodosQuery { ListId = id }); | ||
return Results.File(vm.Content, vm.ContentType, vm.FileName); | ||
}) | ||
.WithName($"{GroupName}_ExportTodos"); ; | ||
|
||
group | ||
.MapPost("/", async (ISender sender, CreateTodoListCommand command) => await sender.Send(command)) | ||
.WithName($"{GroupName}_CreateTodoList"); ; | ||
|
||
group | ||
.MapPut("/{id}", | ||
async (ISender sender, int id, UpdateTodoListCommand command) => | ||
{ | ||
if (id != command.Id) return Results.BadRequest(); | ||
await sender.Send(command); | ||
return Results.NoContent(); | ||
}) | ||
.WithName($"{GroupName}_UpdateTodoList"); ; | ||
|
||
group | ||
.MapDelete("/{id}", | ||
async (ISender sender, int id) => | ||
{ | ||
await sender.Send(new DeleteTodoListCommand(id)); | ||
return Results.NoContent(); | ||
}) | ||
.WithName($"{GroupName}_DeleteTodoList"); ; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.