Add search date range

This commit is contained in:
Pc
2025-05-31 16:03:55 +02:00
parent 89543558b0
commit e47fd77333
2 changed files with 24 additions and 3 deletions

View File

@@ -9,7 +9,9 @@ public record class EventSearchDto
int? OrganisationId,
string? TitleOrDescription,
string? Location,
DateTime? EventDate,
DateTime? EventDateFrom, // zakres daty od
DateTime? EventDateTo, // zakres daty do
ICollection<EventSkill>? EventSkills, // obecnie nie dotyczy
ICollection<EventRegistration>? EventRegistrations // obecnie nie dotyczy
);

View File

@@ -155,14 +155,20 @@ namespace WebApp.Endpoints
{
// Uzyskaj organizację z tokenu
var sort = httpContext.Request.Query["sort"].ToString();
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
Organisation? org = await guhf.GetOrganisationFromToken(token);
List<EventSummaryDto> SearchResults = [];
List<Event> AllEvents = await dbContext.Events.ToListAsync();
AllEvents.Reverse(); // aby wyświetlało od najnowszych wydarzeń
List<Event> AllEvents = await dbContext.Events.ToListAsync();
if (sort is null || sort.ToUpper() != "ASC")
{
AllEvents.Reverse(); // aby wyświetlało od najnowszych wydarzeń
}
foreach(Event e in AllEvents)
{
bool matchFound = true;
@@ -181,6 +187,19 @@ namespace WebApp.Endpoints
if (!TitleMatch && !DescMatch) matchFound = false;
}
//Zakres dat do wyszukiwania
if(query.EventDateFrom is not null)
{
if (e.EventDate < query.EventDateFrom) matchFound = false;
}
if(query.EventDateTo is not null)
{
if (e.EventDate > query.EventDateTo) matchFound = false;
}
// ...
// Jeśli Event jest tym, czego szuka użytkownik,