From cc09cb2156d7e55cd0f5e15ca9e9821d853f7892 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Thu, 16 Oct 2025 23:40:41 +0100 Subject: [PATCH] fix all bug of Arsene's works --- .../Setting/CreateSettingEndpoint.cs | 4 +- .../Setting/DeleteSettingEndpoint.cs | 6 +-- .../Setting/GetAllSettingEndpoint.cs | 3 +- .../Endpoints/Setting/GetSettingEndpoint.cs | 6 +-- ...PatchSettingElectronicSignatureEndpoint.cs | 37 +++++++++++++++++++ .../Setting/PatchSettingLogoEndpoint.cs | 37 +++++++++++++++++++ .../Setting/UpdateSettingEndpoint.cs | 7 ++-- 7 files changed, 86 insertions(+), 14 deletions(-) create mode 100644 PyroFetes/Endpoints/Setting/PatchSettingElectronicSignatureEndpoint.cs create mode 100644 PyroFetes/Endpoints/Setting/PatchSettingLogoEndpoint.cs diff --git a/PyroFetes/Endpoints/Setting/CreateSettingEndpoint.cs b/PyroFetes/Endpoints/Setting/CreateSettingEndpoint.cs index 74bd43f..17e1c86 100644 --- a/PyroFetes/Endpoints/Setting/CreateSettingEndpoint.cs +++ b/PyroFetes/Endpoints/Setting/CreateSettingEndpoint.cs @@ -1,9 +1,7 @@ -using Microsoft.EntityFrameworkCore; - -namespace PyroFetes.Endpoints.Setting; using PyroFetes.DTO.SettingDTO.Request; using PyroFetes.DTO.SettingDTO.Response; using FastEndpoints; +namespace PyroFetes.Endpoints.Setting; public class CreateSettingEndpoint(PyroFetesDbContext database) : Endpoint { diff --git a/PyroFetes/Endpoints/Setting/DeleteSettingEndpoint.cs b/PyroFetes/Endpoints/Setting/DeleteSettingEndpoint.cs index 1d065ed..9db3730 100644 --- a/PyroFetes/Endpoints/Setting/DeleteSettingEndpoint.cs +++ b/PyroFetes/Endpoints/Setting/DeleteSettingEndpoint.cs @@ -1,15 +1,13 @@ -namespace PyroFetes.Endpoint.Setting; -using PyroFetes.DTO.SettingDTO.Request; -using PyroFetes.DTO.SettingDTO.Response; using FastEndpoints; using Microsoft.EntityFrameworkCore; +namespace PyroFetes.Endpoints.Setting; + public class DeleteSettingRequest { public int Id { get; set; } } - public class DeleteSettingEndpoint(PyroFetesDbContext database) : Endpoint { public override void Configure() diff --git a/PyroFetes/Endpoints/Setting/GetAllSettingEndpoint.cs b/PyroFetes/Endpoints/Setting/GetAllSettingEndpoint.cs index 432f824..a674d72 100644 --- a/PyroFetes/Endpoints/Setting/GetAllSettingEndpoint.cs +++ b/PyroFetes/Endpoints/Setting/GetAllSettingEndpoint.cs @@ -1,9 +1,10 @@ -namespace PyroFetes.Endpoints.Setting; using PyroFetes.DTO.SettingDTO.Request; using PyroFetes.DTO.SettingDTO.Response; using FastEndpoints; using Microsoft.EntityFrameworkCore; +namespace PyroFetes.Endpoints.Setting; + public class GetAllSettingEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest> { public override void Configure() diff --git a/PyroFetes/Endpoints/Setting/GetSettingEndpoint.cs b/PyroFetes/Endpoints/Setting/GetSettingEndpoint.cs index 6eda487..6093dfc 100644 --- a/PyroFetes/Endpoints/Setting/GetSettingEndpoint.cs +++ b/PyroFetes/Endpoints/Setting/GetSettingEndpoint.cs @@ -1,8 +1,8 @@ -namespace PyroFetes.Endpoint.Setting; -using PyroFetes.DTO.SettingDTO.Request; -using PyroFetes.DTO.SettingDTO.Response; using FastEndpoints; using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.SettingDTO.Response; + +namespace PyroFetes.Endpoints.Setting; public class GetSettingRequest { diff --git a/PyroFetes/Endpoints/Setting/PatchSettingElectronicSignatureEndpoint.cs b/PyroFetes/Endpoints/Setting/PatchSettingElectronicSignatureEndpoint.cs new file mode 100644 index 0000000..c54d915 --- /dev/null +++ b/PyroFetes/Endpoints/Setting/PatchSettingElectronicSignatureEndpoint.cs @@ -0,0 +1,37 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.SettingDTO.Request; +using PyroFetes.DTO.SettingDTO.Response; + +namespace PyroFetes.Endpoints.Setting; + +public class PatchSettingElectronicSignatureEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Get("/api/setting/{@Id}/ElectronicSignature", x => new {x.Id}); + } + + public override async Task HandleAsync(PatchSettingElectronicSignatureDto 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; + await database.SaveChangesAsync(ct); + + GetSettingDto responseDto = new() + { + Id = setting.Id, + ElectronicSignature = setting.ElectronicSignature, + Logo = setting.Logo + }; + + await Send.OkAsync(responseDto, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Setting/PatchSettingLogoEndpoint.cs b/PyroFetes/Endpoints/Setting/PatchSettingLogoEndpoint.cs new file mode 100644 index 0000000..4bfe5c1 --- /dev/null +++ b/PyroFetes/Endpoints/Setting/PatchSettingLogoEndpoint.cs @@ -0,0 +1,37 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.SettingDTO.Request; +using PyroFetes.DTO.SettingDTO.Response; + +namespace PyroFetes.Endpoints.Setting; + +public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Get("/api/setting/{@Id}/Logo", x => new {x.Id}); + } + + public override async Task HandleAsync(PatchSettingLogoDto req, CancellationToken ct) + { + var setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct); + + if (setting == null) + { + await Send.NotFoundAsync(ct); + return; + } + + 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); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Setting/UpdateSettingEndpoint.cs b/PyroFetes/Endpoints/Setting/UpdateSettingEndpoint.cs index e57b39e..c7758de 100644 --- a/PyroFetes/Endpoints/Setting/UpdateSettingEndpoint.cs +++ b/PyroFetes/Endpoints/Setting/UpdateSettingEndpoint.cs @@ -1,8 +1,9 @@ -namespace PyroFetes.Endpoint.Setting; -using PyroFetes.DTO.SettingDTO.Request; -using PyroFetes.DTO.SettingDTO.Response; using FastEndpoints; using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.SettingDTO.Request; +using PyroFetes.DTO.SettingDTO.Response; + +namespace PyroFetes.Endpoints.Setting; public class UpdateSettingEndpoint(PyroFetesDbContext database) : Endpoint {