b3612f5bec
- Strip /api prefix from all endpoint routes - Make Show.CityId nullable (no longer required FK) - Drop CityId FK constraint and alter column to NULL at startup via raw SQL - Add migration MakeCityIdNullable for schema consistency - Update Show DTOs to reflect nullable CityId Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
48 lines
1.5 KiB
C#
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("/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);
|
|
}
|
|
} |