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,15 @@
using System.ComponentModel.DataAnnotations;
using WebApp.Entities;
namespace WebApp.DTOs;
// Input values in JSON file to create event
public record class EventCreateDto
(
[Required] int? OrganisationId,
[Required][StringLength(50)] string Title,
[StringLength(500)] string Description,
[Required][StringLength(100)] string Location,
[Required] DateTime? EventDate,
ICollection<EventSkill> EventSkills
);

View File

@@ -0,0 +1,17 @@
using System.ComponentModel.DataAnnotations;
using WebApp.Entities;
namespace WebApp.DTOs;
// Output values in JSON file
public record class EventDetailsDto
(
int EventId,
[Required] int? OrganisationId,
[Required][StringLength(50)] string Title,
[StringLength(500)] string Description,
[Required][StringLength(100)] string Location,
[Required] DateTime? EventDate,
ICollection<EventSkill> EventSkills,
ICollection<EventRegistration> EventRegistrations
);

View File

@@ -0,0 +1,16 @@
using System.ComponentModel.DataAnnotations;
using WebApp.Entities;
namespace WebApp.DTOs;
// Output values in JSON file
public record class EventSummaryDto(
int EventId,
[Required] string Organisation,
[Required] [StringLength(50)] string Title,
[StringLength(500)] string Description,
[Required] [StringLength(100)] string Location,
[Required] DateTime? EventDate,
ICollection<EventSkill> EventSkills,
ICollection<EventRegistration> EventRegistrations
);

View File

@@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
using WebApp.Entities;
namespace WebApp.DTOs;
// Input values in JSON file to update event
public record class EventUpdateDto
(
[Required] int? OrganisationId,
[Required][StringLength(50)] string Title,
[StringLength(500)] string Description,
[Required][StringLength(100)] string Location,
[Required] DateTime? EventDate,
ICollection<EventSkill> EventSkills
);

View File

@@ -1,15 +0,0 @@
using System.ComponentModel.DataAnnotations;
using WebApp.Entities;
namespace WebApp.DTOs;
public record class EventsDto(
int EventId,
int OrganisationId, //foreign key
[StringLength(200)] string Title,
[StringLength(800)] string Description,
[StringLength(100)] string Location,
DateTime EventDate,
Organisation? Organisation,
ICollection<EventSkill> EventSkills,
ICollection<EventRegistration> EventRegistrations
);