Using to MinimalAPI

Usunalem EventApiController(dobry byl ale mial problemy).
Dodalem EventsEndpoints, zawiera async, używa Dtos (Data Transfer Objects).
Jeżeli chcecie zrobić HTTP request ale nie wiecie co dać w body JSONa to można sprawdzić w tych Dtos.
EventMapping służy do zmian obiektów Dto na Entity i odwrotnie.
This commit is contained in:
AleksDw
2025-05-09 21:04:27 +02:00
parent 99f2e17a12
commit 31f8cabeb0
10 changed files with 232 additions and 115 deletions

View File

@@ -0,0 +1,64 @@
using Microsoft.EntityFrameworkCore;
using WebApp.DTOs;
using WebApp.Entities;
namespace WebApp.Mapping;
public static class EventMapping
{
public static Event ToEntity(this EventCreateDto ECDto)
{
return new Event()
{
OrganisationId = ECDto.OrganisationId!.Value,
Title = ECDto.Title,
Description = ECDto.Description,
Location = ECDto.Location,
EventDate = DateTime.SpecifyKind(ECDto.EventDate!.Value, DateTimeKind.Utc),
EventSkills = ECDto.EventSkills,
EventRegistrations = []
};
}
public static Event ToEntity(this EventUpdateDto EUDto, int id)
{
return new Event()
{
EventId = id,
OrganisationId = EUDto.OrganisationId!.Value,
Title = EUDto.Title,
Description = EUDto.Description,
Location = EUDto.Location,
EventDate = DateTime.SpecifyKind(EUDto.EventDate!.Value, DateTimeKind.Utc),
EventSkills = EUDto.EventSkills
};
}
public static EventSummaryDto ToEventSummaryDto(this Event myEvent)
{
return new EventSummaryDto(
myEvent.EventId,
myEvent.Organisation!.Name,
myEvent.Title,
myEvent.Description,
myEvent.Location,
myEvent.EventDate,
myEvent.EventSkills,
myEvent.EventRegistrations
);
}
public static EventDetailsDto ToEventDetailsDto(this Event myEvent)
{
return new EventDetailsDto(
myEvent.EventId,
myEvent.OrganisationId,
myEvent.Title,
myEvent.Description,
myEvent.Location,
myEvent.EventDate,
myEvent.EventSkills,
myEvent.EventRegistrations
);
}
}