mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 13:40:13 +01:00
feat: make sorting by date work
This commit is contained in:
@@ -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}",
|
||||
|
||||
Reference in New Issue
Block a user