Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: Immediate.Apis #62

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
using VerticalSliceArchitectureTemplate.Features.Todos.Domain;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using VerticalSliceArchitectureTemplate.Features.Todos.Domain;

namespace VerticalSliceArchitectureTemplate.Features.Todos.Queries;

[MapGet("/todos")]
[Handler]
public sealed partial class GetAllTodos
{
internal static void CustomizeEndpoint(IEndpointConventionBuilder endpoint)
=> endpoint
.WithTags(nameof(Todo));

public sealed record Query(bool? IsCompleted = null);

private static async ValueTask<IReadOnlyList<Todo>> HandleAsync(Query request, AppDbContext dbContext, CancellationToken cancellationToken)
private static async ValueTask<List<Todo>> HandleAsync(Query request, AppDbContext dbContext, CancellationToken cancellationToken)
{
var todos = await dbContext.Todos
.Where(x => request.IsCompleted == null || x.IsCompleted == request.IsCompleted)
.ToListAsync(cancellationToken);

return todos.AsReadOnly();
return todos;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace VerticalSliceArchitectureTemplate.Features.Todos.Queries;

[MapGet("/todos/{id:guid}")]
[Handler]
public sealed partial class GetTodo
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace VerticalSliceArchitectureTemplate.Features.Todos.WebApi;

public class TodoEndpoints : IEndpoints
public class TodoEndpoints
{
public static void MapEndpoints(IEndpointRouteBuilder endpoints)
{
Expand Down Expand Up @@ -64,7 +64,7 @@ await handler.HandleAsync(command with
.WithTags(nameof(Todo));

group.MapGet("/{id:guid}",
(Guid id, GetTodo.Handler handler, CancellationToken cancellationToken)
(Guid id, [FromRoute] GetTodo.Handler handler, CancellationToken cancellationToken)
=> handler.HandleAsync(new GetTodo.Query(id), cancellationToken))
.Produces<Todo>()
.Produces(StatusCodes.Status404NotFound)
Expand Down
3 changes: 2 additions & 1 deletion src/VerticalSliceArchitectureTemplate/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
global using VerticalSliceArchitectureTemplate.Common.Exceptions;
global using VerticalSliceArchitectureTemplate.Common.Features;
global using VerticalSliceArchitectureTemplate.Common.Persistence;
global using Immediate.Handlers.Shared;
global using Immediate.Handlers.Shared;
global using Immediate.Apis.Shared;
37 changes: 0 additions & 37 deletions src/VerticalSliceArchitectureTemplate/Host/EndpointDiscovery.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/VerticalSliceArchitectureTemplate/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@

app.UseProductionExceptionHandler();

app.RegisterEndpoints(appAssembly);
app.MapVerticalSliceArchitectureTemplateEndpoints();

app.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Immediate.Apis" Version="0.4.0" />
<PackageReference Include="Immediate.Handlers" Version="1.2.0" />
<PackageReference Include="MediatR" Version="12.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0"/>
Expand Down