-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathEndpoint.cs
32 lines (30 loc) · 1023 Bytes
/
Endpoint.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using HappyCode.NetCoreBoilerplate.BooksModule.Dtos;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using System.Data;
namespace HappyCode.NetCoreBoilerplate.BooksModule.Features.GetBook;
internal static class Endpoint
{
public static IEndpointRouteBuilder MapGetBookEndpoint(this IEndpointRouteBuilder endpoints)
{
endpoints
.MapGet(
"/{id:int}",
async (
int id,
IDbConnection db,
CancellationToken ct
) =>
{
var book = await db.GetBookAsync(id, ct);
return book.Id is not null
? Results.Ok(book)
: Results.NotFound();
})
.Produces<BookDto>()
.Produces(StatusCodes.Status404NotFound)
.WithTags("Books");
return endpoints;
}
}