feat: make sorting by date work

This commit is contained in:
2025-05-18 20:39:47 +02:00
parent 8ffb7f4eff
commit e0e6fa0573
4 changed files with 81 additions and 34 deletions

View File

@@ -17,14 +17,30 @@ namespace WebApp.Endpoints
.WithParameterValidation();
// GET /events
group.MapGet("/",
async (ApplicationDbContext dbContext, HttpContext httpContext) =>
await dbContext.Events
.Include(Eve => Eve.Organisation)
.OrderByDescending(Eve => Eve.EventId)
.Select(Eve => Eve.ToEventSummaryDto()) //EventSummaryDto
.AsNoTracking()
.ToListAsync());
group.MapGet("/",
async (ApplicationDbContext dbContext, HttpContext httpContext) =>
{
var sort = httpContext.Request.Query["sort"].ToString();
IOrderedQueryable<Event> res;
var r = dbContext.Events
.Include(Eve => Eve.Organisation);
if (sort is not null && sort.ToUpper() == "ASC")
{
res = r.OrderBy(Eve => Eve.EventId);
}
else
{
res = r.OrderByDescending(Eve => Eve.EventId);
}
return await res
.Select(Eve => Eve.ToEventSummaryDto()) //EventSummaryDto
.AsNoTracking()
.ToListAsync();
});
// GET /events/1
group.MapGet("/{id}",