Files
PF3-fork/PyroFetes/Endpoints/Staff/UpdateStaffEndpoint.cs
T
cernont 6c1330e570 Fix FastEndpoints/Swagger wiring and missing required fields in DTOs
- 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>
2026-05-27 19:35:01 +02:00

48 lines
1.5 KiB
C#

using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Staff.Request;
using PyroFetes.DTO.Staff.Response;
namespace PyroFetes.Endpoints.Staff;
public class UpdateStaffEndpoint(PyroFetesDbContext pf3DbContext) : Endpoint<UpdateStaffDto, ReadStaffDto>
{
public override void Configure()
{
Put("/api/staff/{Id}");
AllowAnonymous();
}
public override async Task HandleAsync(UpdateStaffDto req, CancellationToken ct)
{
var staff = await pf3DbContext.Staffs.FirstOrDefaultAsync(s => s.Id == req.Id, ct);
if (staff is null)
{
await Send.NotFoundAsync(ct);
return;
}
staff.FirstName = req.FirstName ?? staff.FirstName;
staff.LastName = req.LastName ?? staff.LastName;
staff.Profession = req.Profession ?? staff.Profession;
staff.Email = req.Email ?? staff.Email;
staff.F4T2NumberApproval = req.F4T2NumberApproval ?? staff.F4T2NumberApproval;
if (req.F4T2ExpirationDate.HasValue)
staff.F4T2ExpirationDate = req.F4T2ExpirationDate.Value;
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);
}
}