Creating setting's endpoints

This commit is contained in:
2025-10-16 17:39:36 +02:00
parent d0f20e08f0
commit 0121435594
7 changed files with 180 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
namespace PyroFetes.Endpoint.Setting;
using PyroFetes.DTO.SettingDTO.Request;
using PyroFetes.DTO.SettingDTO.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
public class UpdateSettingEndpoint(PyroFetesDbContext database) : Endpoint<UpdateSettingDto, GetSettingDto>
{
public override void Configure()
{
Get("/api/setting/{@Id}", x => new {x.Id});
}
public override async Task HandleAsync(UpdateSettingDto req, CancellationToken ct)
{
var setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (setting == null)
{
await Send.NotFoundAsync(ct);
return;
}
setting.ElectronicSignature = req.ElectronicSignature;
setting.Logo = req.Logo;
await database.SaveChangesAsync(ct);
GetSettingDto responseDto = new()
{
Id = setting.Id,
ElectronicSignature = setting.ElectronicSignature,
Logo = setting.Logo
};
await Send.OkAsync(responseDto, ct);
}
}