-
-
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.
- Loading branch information
1 parent
d88bff0
commit 83e31a7
Showing
12 changed files
with
133 additions
and
70 deletions.
There are no files selected for viewing
This file was deleted.
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,43 @@ | ||
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; | ||
|
||
namespace CleanArchitecture.WebUI.Endpoints; | ||
|
||
public class TodoListsEndpointGroup : EndpointGroupBase | ||
{ | ||
public override void Map(WebApplication app) | ||
{ | ||
MapGroup("TodoLists", app); | ||
|
||
MapGet("GetTodoLists", | ||
async (ISender sender) => await sender.Send(new GetTodosQuery())); | ||
|
||
MapGet("ExportTodos", "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); | ||
}); | ||
|
||
MapPost("CreateTodoList", | ||
async (ISender sender, CreateTodoListCommand command) => await sender.Send(command)); | ||
|
||
MapPut("UpdateTodoList", "{id}", | ||
async (ISender sender, int id, UpdateTodoListCommand command) => | ||
{ | ||
if (id != command.Id) return Results.BadRequest(); | ||
await sender.Send(command); | ||
return Results.NoContent(); | ||
}); | ||
|
||
MapDelete("DeleteTodoList", "{id}", | ||
async (ISender sender, int id) => | ||
{ | ||
await sender.Send(new DeleteTodoListCommand(id)); | ||
return Results.NoContent(); | ||
}); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using CleanArchitecture.WebUI.Filters; | ||
|
||
namespace CleanArchitecture.WebUI.Infrastructure; | ||
|
||
public abstract class EndpointGroupBase | ||
{ | ||
private string? _groupName; | ||
private RouteGroupBuilder? _group; | ||
|
||
public abstract void Map(WebApplication app); | ||
|
||
protected void MapGroup(string groupName, WebApplication app) | ||
{ | ||
_groupName = groupName; | ||
|
||
_group = app | ||
.MapGroup($"/api/{_groupName}") | ||
.WithGroupName(_groupName) | ||
.WithTags(_groupName) | ||
.RequireAuthorization() | ||
.WithOpenApi() | ||
.AddEndpointFilter<ApiExceptionFilter>(); | ||
} | ||
|
||
protected void MapGet(string name, Delegate handler) | ||
{ | ||
MapGet(name, "", handler); | ||
} | ||
|
||
protected void MapGet(string name, string prefix, Delegate handler) | ||
{ | ||
_group!.MapGet(prefix, handler) | ||
.WithName(GetEndpointName(name)); | ||
} | ||
|
||
protected void MapPost(string name, Delegate handler) | ||
{ | ||
MapPost(name, "", handler); | ||
} | ||
|
||
protected void MapPost(string name, string prefix, Delegate handler) | ||
{ | ||
_group!.MapPost(prefix, handler) | ||
.WithName(GetEndpointName(name)); | ||
} | ||
|
||
protected void MapPut(string name, string prefix, Delegate handler) | ||
{ | ||
_group!.MapPut(prefix, handler) | ||
.WithName(GetEndpointName(name)); | ||
} | ||
|
||
protected void MapDelete(string name, string prefix, Delegate handler) | ||
{ | ||
_group!.MapDelete(prefix, handler) | ||
.WithName(GetEndpointName(name)); | ||
} | ||
|
||
private string GetEndpointName(string name) => $"{_groupName}_{name}"; | ||
} |
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 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 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 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