mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 13:40:13 +01:00
meta: add some comments, as said in a comment inside LAH-14
This commit is contained in:
@@ -29,17 +29,33 @@ namespace WebApp.Endpoints
|
|||||||
{
|
{
|
||||||
Event? Eve = await dbContext.Events.FindAsync(id);
|
Event? Eve = await dbContext.Events.FindAsync(id);
|
||||||
|
|
||||||
|
if (Eve is null) return Results.NotFound();
|
||||||
|
|
||||||
return Eve is null ?
|
// Sprawdź, czy token należy do organizacji, a jeżeli tak, to do której.
|
||||||
Results.NotFound() : Results.Ok(Eve.ToEventDetailsDto()); //EventDetailsDto
|
// ...
|
||||||
|
|
||||||
|
// 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);
|
.WithName(GetEventEndpointName);
|
||||||
|
|
||||||
// POST /events
|
// POST /events
|
||||||
group.MapPost("/", async (EventCreateDto newEvent, ApplicationDbContext dbContext) =>
|
group.MapPost("/", async (EventCreateDto newEvent, ApplicationDbContext dbContext) =>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Uzyskaj organizację z tokenu
|
||||||
|
// ...
|
||||||
|
|
||||||
Event Eve = newEvent.ToEntity();
|
Event Eve = newEvent.ToEntity();
|
||||||
|
|
||||||
|
// Wyzeruj EventRegistrations, ponieważ nie są to dane,
|
||||||
|
// które powinniśmy przyjmować bez zgody wolontariuszy!
|
||||||
|
// ...
|
||||||
|
|
||||||
dbContext.Events.Add(Eve);
|
dbContext.Events.Add(Eve);
|
||||||
await dbContext.SaveChangesAsync();
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
@@ -59,6 +75,17 @@ namespace WebApp.Endpoints
|
|||||||
return Results.NotFound();
|
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)
|
dbContext.Entry(existingEvent)
|
||||||
.CurrentValues
|
.CurrentValues
|
||||||
@@ -76,6 +103,14 @@ namespace WebApp.Endpoints
|
|||||||
// DELETE /events/1
|
// DELETE /events/1
|
||||||
group.MapDelete("/{id}", async (int id, ApplicationDbContext dbContext) =>
|
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
|
await dbContext.Events
|
||||||
.Where(Eve => Eve.EventId == id)
|
.Where(Eve => Eve.EventId == id)
|
||||||
.ExecuteDeleteAsync();
|
.ExecuteDeleteAsync();
|
||||||
|
|||||||
Reference in New Issue
Block a user