6c1330e570
- Register FastEndpoints, SwaggerDocument, DbContext in Program.cs - Add DbContextOptions constructor to PyroFetesDbContext - Add CityId to Show DTOs and endpoints (NOT NULL in DB) - Add F4T2NumberApproval/F4T2ExpirationDate to Staff DTOs and endpoints - Simplify DeleteShow to rely on DB cascade instead of manual includes - Default NOT NULL string fields to empty string on create Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using FastEndpoints;
|
|
using PyroFetes.DTO.Staff.Request;
|
|
using PyroFetes.DTO.Staff.Response;
|
|
|
|
namespace PyroFetes.Endpoints.Staff;
|
|
|
|
public class CreateStaffEndpoint(PyroFetesDbContext pf3DbContext):Endpoint<CreateStaffDto, ReadStaffDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Post("/api/staff");
|
|
AllowAnonymous();
|
|
}
|
|
|
|
public override async Task HandleAsync(CreateStaffDto req, CancellationToken ct)
|
|
{
|
|
var staff = new PyroFetes.Models.Staff
|
|
{
|
|
FirstName = req.FirstName,
|
|
LastName = req.LastName,
|
|
Profession = req.Profession,
|
|
Email = req.Email,
|
|
F4T2NumberApproval = req.F4T2NumberApproval,
|
|
F4T2ExpirationDate = req.F4T2ExpirationDate
|
|
};
|
|
|
|
pf3DbContext.Staffs.Add(staff);
|
|
await pf3DbContext.SaveChangesAsync(ct);
|
|
|
|
var result = new ReadStaffDto()
|
|
{
|
|
Id = staff.Id,
|
|
FirstName = staff.FirstName,
|
|
LastName = staff.LastName,
|
|
Profession = staff.Profession,
|
|
Email = staff.Email,
|
|
F4T2NumberApproval = staff.F4T2NumberApproval,
|
|
F4T2ExpirationDate = staff.F4T2ExpirationDate
|
|
};
|
|
|
|
await Send.OkAsync(result, ct);
|
|
|
|
}
|
|
} |