fix: offload building DTOs to GUHF

DTO building allows for fully returning correct event's
skills and registrations
This commit is contained in:
2025-06-01 20:33:58 +02:00
parent 426288d728
commit efb71b24d3
10 changed files with 182 additions and 72 deletions

View File

@@ -1,4 +1,4 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using WebApp.DTOs;
using WebApp.Entities;
@@ -34,20 +34,21 @@ public static class EventMapping
public static EventSummaryDto ToEventSummaryDto(this Event myEvent)
{
return new EventSummaryDto(
myEvent.EventId,
myEvent.Organisation!.Name,
myEvent.OrganisationId,
myEvent.Title,
myEvent.Description,
myEvent.Location,
myEvent.EventDate,
myEvent.EventSkills,
myEvent.EventRegistrations
);
return new EventSummaryDto {
EventId = myEvent.EventId,
Organisation = myEvent.Organisation!.Name,
OrganisationId = myEvent.OrganisationId,
Title = myEvent.Title,
Description = myEvent.Description,
Location = myEvent.Location,
EventDate = myEvent.EventDate,
EventSkills = myEvent.EventSkills,
EventRegistrations = myEvent.EventRegistrations
};
}
public static EventSummaryNoErDto ToEventSummaryNoErDto(this Event myEvent)
{
return new EventSummaryNoErDto(
myEvent.EventId,
myEvent.Organisation!.Name,
@@ -60,18 +61,42 @@ public static class EventMapping
);
}
public static EventRegistrationDto ToEventRegistrationDto(this EventRegistration myER)
{
return new EventRegistrationDto {
EventId = myER.EventId,
UserId = myER.UserId,
UserName = myER.User.FirstName + " " + myER.User.LastName,
RegisteredAt = myER.RegisteredAt
};
}
public static EventDetailsDto ToEventDetailsDto(this Event myEvent)
{
return new EventDetailsDto(
myEvent.EventId,
myEvent.OrganisationId,
myEvent.Organisation.Name,
myEvent.Title,
myEvent.Description,
myEvent.Location,
myEvent.EventDate,
myEvent.EventSkills,
myEvent.EventRegistrations
);
List<SkillSummaryDto> ssdto = new List<SkillSummaryDto>();
List<EventRegistrationDto> erdto = new List<EventRegistrationDto>();
foreach (EventSkill es in myEvent.EventSkills)
{
ssdto.Add(es.ToSkillSummaryDto());
}
foreach (EventRegistration er in myEvent.EventRegistrations)
{
erdto.Add(er.ToEventRegistrationDto());
}
return new EventDetailsDto {
EventId = myEvent.EventId,
OrganisationId = myEvent.OrganisationId,
OrganisationName = myEvent.Organisation.Name,
Title = myEvent.Title,
Description = myEvent.Description,
Location = myEvent.Location,
EventDate = myEvent.EventDate,
EventSkills = ssdto,
EventRegistrations = erdto
};
}
}
}

View File

@@ -13,4 +13,12 @@ public static class EventSkillMapping
SkillId = SSDto.Skill,
};
}
public static SkillSummaryDto ToSkillSummaryDto(this EventSkill es)
{
return new SkillSummaryDto{
SkillId = es.SkillId,
SkillName = es.Skill.Name
};
}
}

View File

@@ -1,4 +1,4 @@
using WebApp.DTOs;
using WebApp.DTOs;
using WebApp.Entities;
namespace WebApp.Mapping
@@ -16,10 +16,10 @@ namespace WebApp.Mapping
public static SkillSummaryDto ToSkillSummaryDto(this Skill s)
{
return new SkillSummaryDto(
s.SkillId,
s.Name
);
return new SkillSummaryDto {
SkillId = s.SkillId,
SkillName = s.Name
};
}
}
}