mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 13:40:13 +01:00
fix: offload building DTOs to GUHF
DTO building allows for fully returning correct event's skills and registrations
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.Intrinsics.Arm;
|
||||
using WebApp.Data;
|
||||
using WebApp.DTOs;
|
||||
using WebApp.Entities;
|
||||
@@ -40,14 +42,17 @@ namespace WebApp.Endpoints
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
});
|
||||
|
||||
|
||||
|
||||
// GET /events/1
|
||||
group.MapGet("/{id}",
|
||||
group.MapGet("/{id}",
|
||||
async (int id, ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
|
||||
{
|
||||
Event? Eve = await dbContext.Events.FindAsync(id);
|
||||
|
||||
Event? Eve = await dbContext
|
||||
.Events
|
||||
.Include(e => e.Organisation)
|
||||
.FirstOrDefaultAsync(e => e.EventId == id);
|
||||
if (Eve is null) return Results.NotFound();
|
||||
|
||||
// Sprawdź, czy token należy do organizacji, a jeżeli tak, to do której.
|
||||
@@ -55,16 +60,14 @@ namespace WebApp.Endpoints
|
||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||
|
||||
// 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!
|
||||
if (org is null || org.OrganisationId != Eve.OrganisationId) Eve.EventRegistrations = [];
|
||||
// to zwróć także EventRegistrations. W przeciwnym razie niech będzie to
|
||||
// puste pole.
|
||||
List<EventDetailsDto> result = await guhf.BuildDetailedEventsDto(
|
||||
dbContext,
|
||||
(org is not null && Eve.Organisation == org)
|
||||
);
|
||||
|
||||
// DLACZEGO?
|
||||
Eve.Organisation = await guhf.GetOrganisationFromId(Eve.OrganisationId);
|
||||
|
||||
EventDetailsDto EveDto = Eve.ToEventDetailsDto();
|
||||
|
||||
return Results.Ok(EveDto); //EventDetailsDto
|
||||
return Results.Ok(result.FirstOrDefault(e => e.EventId == id));
|
||||
})
|
||||
.WithName(GetEventEndpointName);
|
||||
|
||||
@@ -214,6 +217,9 @@ namespace WebApp.Endpoints
|
||||
|
||||
// UWAGA! TO NIE POWINNO TAK DZIAŁAĆ!
|
||||
// KTOKOLWIEK WIDZIAŁ, KTOKOLWIEK WIE CZEMU Organisation JEST null?
|
||||
//
|
||||
// Odpowiedź: Bo pobieramy dane bez .Include(e => e.Organisation),
|
||||
// co zapobiega masie innych problemów, m.in. rekurencyjnym importom.
|
||||
e.Organisation = await guhf.GetOrganisationFromId(e.OrganisationId);
|
||||
|
||||
if (matchFound) SearchResults.Add(e.ToEventSummaryDto());
|
||||
|
||||
Reference in New Issue
Block a user