using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.ExperienceLevel.Request; using PyroFetes.DTO.ExperienceLevel.Response; namespace PyroFetes.Endpoints.ExperienceLevel; public class UpdateExperienceLevelEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint { public override void Configure() { Put ("/api/ExperienceLevels/{@Id}", x => new { x.Id }); AllowAnonymous(); } public override async Task HandleAsync(UpdateExperienceLevelDto req, CancellationToken ct) { Models.ExperienceLevel? databaseExperienceLevel = await pyroFetesDbContext.ExperienceLevels.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); if (databaseExperienceLevel == null) { await Send.NotFoundAsync(ct); return; } else { databaseExperienceLevel.Label = req.Label; } await pyroFetesDbContext.SaveChangesAsync(ct); GetExperienceLevelDto dto = new() { Id = databaseExperienceLevel.Id, Label = req.Label, }; await Send.OkAsync(dto, ct); } }