Refactored Setting

This commit is contained in:
Cristiano
2025-11-20 15:05:44 +01:00
parent ee9b4675dd
commit 8325aa0768
7 changed files with 53 additions and 47 deletions

View File

@@ -3,10 +3,14 @@ using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.SettingDTO.Request;
using PyroFetes.DTO.SettingDTO.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Settings;
namespace PyroFetes.Endpoints.Settings;
public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint<PatchSettingLogoDto, GetSettingDto>
public class PatchSettingLogoEndpoint(
SettingsRepository settingsRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchSettingLogoDto, GetSettingDto>
{
public override void Configure()
{
@@ -16,7 +20,7 @@ public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint<Pa
public override async Task HandleAsync(PatchSettingLogoDto req, CancellationToken ct)
{
Setting? setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
if (setting == null)
{
@@ -25,15 +29,8 @@ public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint<Pa
}
setting.Logo = req.Logo;
await database.SaveChangesAsync(ct);
GetSettingDto responseDto = new()
{
Id = setting.Id,
ElectronicSignature = setting.ElectronicSignature,
Logo = setting.Logo
};
await settingsRepository.UpdateAsync(setting, ct);
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
}
}