-
-
Notifications
You must be signed in to change notification settings - Fork 96
/
Endpoint.cs
31 lines (29 loc) · 1002 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
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using System.Data;
namespace HappyCode.NetCoreBoilerplate.BooksModule.Features.DeleteBook;
internal static class Endpoint
{
public static IEndpointRouteBuilder MapDeleteBookEndpoint(this IEndpointRouteBuilder endpoints)
{
endpoints
.MapDelete(
"/{id:int}",
async (
int id,
IDbConnection db,
CancellationToken ct
) =>
{
var affected = await db.DeleteBookAsync(id, ct);
return affected > 0
? Results.NoContent()
: Results.NotFound();
})
.Produces(StatusCodes.Status204NoContent)
.Produces(StatusCodes.Status404NotFound)
.WithTags("Books");
return endpoints;
}
}