-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEndpoint.cs
More file actions
41 lines (35 loc) · 1.13 KB
/
Copy pathEndpoint.cs
File metadata and controls
41 lines (35 loc) · 1.13 KB
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
33
34
35
36
37
38
39
40
41
using Microsoft.EntityFrameworkCore;
using Panner;
using Panner.AspNetCore.Samples.FastEndpointsNet9.EFModel;
using Views = Panner.AspNetCore.Samples.FastEndpointsNet9.Views;
using Panner.AspNetCore.Samples.FastEndpointsNet9.PannerExtensions;
namespace Posts;
sealed class Endpoint : Endpoint<Request, IEnumerable<Views.Post>>
{
private readonly BlogContext _context;
public Endpoint(BlogContext context)
{
_context = context;
}
public override void Configure()
{
Get("/posts");
AllowAnonymous();
}
public override async Task HandleAsync(Request r, CancellationToken c)
{
_context.Database.EnsureCreated();
var result = await _context.Posts
.Apply(r.Filters ?? Array.Empty<IFilterParticle<Post>>())
.Apply(r.Sorts ?? Array.Empty<ISortParticle<Post>>())
.Select(x => new Views.Post
{
Id = x.Id,
Title = x.Title,
Content = x.Content,
Creation = x.CreatedOn
})
.ToArrayAsync(c);
await SendAsync(result, cancellation: c);
}
}