Last active
January 17, 2024 03:42
-
-
Save dj-nitehawk/5b3e73818f630c2fe90d9f4674847452 to your computer and use it in GitHub Desktop.
Endpoint Grouping With FastEndpoints
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
using FastEndpoints; | |
using FastEndpoints.Swagger; | |
var bld = WebApplication.CreateBuilder(); | |
bld.Services | |
.AddAuthorization() | |
.AddFastEndpoints() | |
.SwaggerDocument(o => o.AutoTagPathSegmentIndex = 0); | |
var app = bld.Build(); | |
app.UseAuthorization() | |
.UseFastEndpoints() | |
.UseSwaggerGen(); | |
app.Run(); | |
public class Administration : Group | |
{ | |
public Administration() | |
{ | |
Configure( | |
"admin", | |
ep => | |
{ | |
ep.Description( | |
x => x.Produces(401) | |
.WithTags("administration")); | |
}); | |
} | |
} | |
public class Login : EndpointWithoutRequest | |
{ | |
public override void Configure() | |
{ | |
Get("/login"); | |
Group<Administration>(); | |
} | |
public override async Task HandleAsync(CancellationToken c) | |
{ | |
await SendOkAsync(); | |
} | |
} | |
public class Sales : SubGroup<Administration> | |
{ | |
public Sales() | |
{ | |
Configure( | |
"sales", | |
ep => | |
{ | |
ep.Description( | |
x => x.Produces(402) | |
.WithTags("sales")); | |
}); | |
} | |
} | |
public class GetInvoice : EndpointWithoutRequest | |
{ | |
public override void Configure() | |
{ | |
Get("/invoice/{id}"); | |
Group<Sales>(); | |
} | |
public override async Task HandleAsync(CancellationToken c) | |
{ | |
await SendOkAsync(); | |
} | |
} | |
public class Reports : SubGroup<Sales> | |
{ | |
public Reports() | |
{ | |
Configure( | |
"reports", | |
ep => | |
{ | |
ep.Description( | |
x => x.Produces(403) | |
.WithTags("sales-reports")); | |
}); | |
} | |
} | |
public class TotalTurnover : EndpointWithoutRequest | |
{ | |
public override void Configure() | |
{ | |
Get("/turnover/{month}"); | |
Group<Reports>(); | |
} | |
public override async Task HandleAsync(CancellationToken c) | |
{ | |
await SendOkAsync(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment