meta: add some comments, as said in a comment inside LAH-14

This commit is contained in:
2025-05-10 19:02:40 +02:00
parent 38e3cf06b9
commit 48fed2ee5d

View File

@@ -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();