From 48fed2ee5d8aaeda6c7fd0f69c7bd1099a1685b3 Mon Sep 17 00:00:00 2001 From: eee4 <41441600+eee4@users.noreply.github.com> Date: Sat, 10 May 2025 19:02:40 +0200 Subject: [PATCH] meta: add some comments, as said in a comment inside LAH-14 --- WebApp/Endpoints/EventsEndpoints.cs | 39 +++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/WebApp/Endpoints/EventsEndpoints.cs b/WebApp/Endpoints/EventsEndpoints.cs index d60bc00..bcfd761 100644 --- a/WebApp/Endpoints/EventsEndpoints.cs +++ b/WebApp/Endpoints/EventsEndpoints.cs @@ -29,17 +29,33 @@ namespace WebApp.Endpoints { Event? Eve = await dbContext.Events.FindAsync(id); + if (Eve is null) return Results.NotFound(); - return Eve is null ? - Results.NotFound() : Results.Ok(Eve.ToEventDetailsDto()); //EventDetailsDto + // Sprawdź, czy token należy do organizacji, a jeżeli tak, to do której. + // ... + + // Jeśli token należy do organizacji, która utworzyła to wydarzenie, + // to zwróć także EventRegistrations. W przeciwnym razie usuń to pole + // przed jego wysłaniem! + // ... + + return Results.Ok(Eve.ToEventDetailsDto()); //EventDetailsDto }) .WithName(GetEventEndpointName); // POST /events group.MapPost("/", async (EventCreateDto newEvent, ApplicationDbContext dbContext) => { + + // Uzyskaj organizację z tokenu + // ... + Event Eve = newEvent.ToEntity(); + // Wyzeruj EventRegistrations, ponieważ nie są to dane, + // które powinniśmy przyjmować bez zgody wolontariuszy! + // ... + dbContext.Events.Add(Eve); await dbContext.SaveChangesAsync(); @@ -59,6 +75,17 @@ namespace WebApp.Endpoints return Results.NotFound(); } + // Uzyskaj organizację z tokenu + // ... + + // Sprawdź, czy organizacja ma prawo + // do zmodyfikowania tego (EventId = id) eventu. + // ... + + // Nadpisz organisationId (obecne w updatedEvent, + // lecz nie sprawdzane poniżej) na to, co odczytaliśmy + // do existingEvent. + // ... dbContext.Entry(existingEvent) .CurrentValues @@ -76,6 +103,14 @@ namespace WebApp.Endpoints // DELETE /events/1 group.MapDelete("/{id}", async (int id, ApplicationDbContext dbContext) => { + + // Uzyskaj organizację z tokenu + // ... + + // Sprawdź, czy organizacja ma prawo + // do usunięcia tego (EventId = id) eventu. + // ... + await dbContext.Events .Where(Eve => Eve.EventId == id) .ExecuteDeleteAsync();