diff --git a/PyroFetes/DTO/SettingDTO/Request/PatchSettingElectronicSignatureDto.cs b/PyroFetes/DTO/SettingDTO/Request/PatchSettingElectronicSignatureDto.cs index 2240628..fe2c421 100644 --- a/PyroFetes/DTO/SettingDTO/Request/PatchSettingElectronicSignatureDto.cs +++ b/PyroFetes/DTO/SettingDTO/Request/PatchSettingElectronicSignatureDto.cs @@ -2,6 +2,5 @@ namespace PyroFetes.DTO.SettingDTO.Request; public class PatchSettingElectronicSignatureDto { - public int Id { get; set; } public IFormFile? ElectronicSignature { get; set; } } \ No newline at end of file diff --git a/PyroFetes/DTO/SettingDTO/Request/PatchSettingLogoDto.cs b/PyroFetes/DTO/SettingDTO/Request/PatchSettingLogoDto.cs index 24963df..24f1b8e 100644 --- a/PyroFetes/DTO/SettingDTO/Request/PatchSettingLogoDto.cs +++ b/PyroFetes/DTO/SettingDTO/Request/PatchSettingLogoDto.cs @@ -2,6 +2,5 @@ namespace PyroFetes.DTO.SettingDTO.Request; public class PatchSettingLogoDto { - public int Id { get; set; } public IFormFile? Logo { get; set; } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs b/PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs deleted file mode 100644 index dda0bd1..0000000 --- a/PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs +++ /dev/null @@ -1,35 +0,0 @@ -using FastEndpoints; -using PyroFetes.DTO.SettingDTO.Request; -using PyroFetes.Models; -using PyroFetes.Repositories; - -namespace PyroFetes.Endpoints.Settings; - -public class CreateSettingEndpoint(SettingsRepository settingsRepository) : Endpoint -{ - public override void Configure() - { - Post("/settings"); - AllowAnonymous(); - } - - public override async Task HandleAsync(CreateSettingDto req, CancellationToken ct) - { - // Encodage en base64 - using MemoryStream memoryStream = new(); - if (req.Logo != null) await req.Logo.CopyToAsync(memoryStream, ct); - byte[] logoBytes = memoryStream.ToArray(); - - if (req.ElectronicSignature != null) await req.ElectronicSignature.CopyToAsync(memoryStream, ct); - byte[] signatureBytes = memoryStream.ToArray(); - - Setting setting = new() - { - ElectronicSignature = Convert.ToBase64String(signatureBytes), - Logo = Convert.ToBase64String(logoBytes) - }; - - await settingsRepository.AddAsync(setting, ct); - await Send.NoContentAsync(ct); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Settings/DeleteSettingEndpoint.cs b/PyroFetes/Endpoints/Settings/DeleteSettingEndpoint.cs deleted file mode 100644 index 319acf9..0000000 --- a/PyroFetes/Endpoints/Settings/DeleteSettingEndpoint.cs +++ /dev/null @@ -1,34 +0,0 @@ -using FastEndpoints; -using PyroFetes.Models; -using PyroFetes.Repositories; -using PyroFetes.Specifications.Settings; - -namespace PyroFetes.Endpoints.Settings; - -public class DeleteSettingRequest -{ - public int Id { get; set; } -} - -public class DeleteSettingEndpoint(SettingsRepository settingsRepository) : Endpoint -{ - public override void Configure() - { - Delete("/settings/{@Id}", x => new { x.Id }); - AllowAnonymous(); - } - - public override async Task HandleAsync(DeleteSettingRequest req, CancellationToken ct) - { - Setting? setting = await settingsRepository.SingleOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct); - - if (setting is null) - { - await Send.NotFoundAsync(ct); - return; - } - - await settingsRepository.DeleteAsync(setting, ct); - await Send.NoContentAsync(ct); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Settings/GetSettingEndpoint.cs b/PyroFetes/Endpoints/Settings/GetSettingEndpoint.cs index a36dcd9..e10ce01 100644 --- a/PyroFetes/Endpoints/Settings/GetSettingEndpoint.cs +++ b/PyroFetes/Endpoints/Settings/GetSettingEndpoint.cs @@ -2,28 +2,20 @@ using PyroFetes.DTO.SettingDTO.Response; using PyroFetes.Models; using PyroFetes.Repositories; -using PyroFetes.Specifications.Settings; namespace PyroFetes.Endpoints.Settings; -public class GetSettingRequest -{ - public int Id { get; set; } -} - -public class GetSettingEndpoint( - SettingsRepository settingsRepository, - AutoMapper.IMapper mapper) : Endpoint +public class GetSettingEndpoint(SettingsRepository settingsRepository, AutoMapper.IMapper mapper) : EndpointWithoutRequest { public override void Configure() { - Get("/settings/{@Id}", x => new { x.Id }); + Get("/settings/"); AllowAnonymous(); } - public override async Task HandleAsync(GetSettingRequest req, CancellationToken ct) + public override async Task HandleAsync(CancellationToken ct) { - Setting? setting = await settingsRepository.SingleOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct); + Setting? setting = await settingsRepository.FirstOrDefaultAsync(ct); if (setting is null) { diff --git a/PyroFetes/Endpoints/Settings/PatchSettingElectronicSignatureEndpoint.cs b/PyroFetes/Endpoints/Settings/PatchSettingElectronicSignatureEndpoint.cs index 5588935..efd1808 100644 --- a/PyroFetes/Endpoints/Settings/PatchSettingElectronicSignatureEndpoint.cs +++ b/PyroFetes/Endpoints/Settings/PatchSettingElectronicSignatureEndpoint.cs @@ -2,7 +2,6 @@ using PyroFetes.DTO.SettingDTO.Request; using PyroFetes.Models; using PyroFetes.Repositories; -using PyroFetes.Specifications.Settings; namespace PyroFetes.Endpoints.Settings; @@ -10,13 +9,14 @@ public class PatchSettingElectronicSignatureEndpoint(SettingsRepository settings { public override void Configure() { - Patch("/settings/{@Id}/ElectronicSignature", x => new { x.Id }); + Patch("/settings/electronicSignature"); + AllowFormData(); AllowAnonymous(); } public override async Task HandleAsync(PatchSettingElectronicSignatureDto req, CancellationToken ct) { - Setting? setting = await settingsRepository.SingleOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct); + Setting? setting = await settingsRepository.FirstOrDefaultAsync(ct); if (setting is null) { diff --git a/PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs b/PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs index 84de016..4047f19 100644 --- a/PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs +++ b/PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs @@ -2,7 +2,6 @@ using PyroFetes.DTO.SettingDTO.Request; using PyroFetes.Models; using PyroFetes.Repositories; -using PyroFetes.Specifications.Settings; namespace PyroFetes.Endpoints.Settings; @@ -10,13 +9,14 @@ public class PatchSettingLogoEndpoint(SettingsRepository settingsRepository) : E { public override void Configure() { - Patch("/settings/{@Id}/logo", x => new { x.Id }); + Patch("/settings/logo"); + AllowFormData(); AllowAnonymous(); } public override async Task HandleAsync(PatchSettingLogoDto req, CancellationToken ct) { - Setting? setting = await settingsRepository.SingleOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct); + Setting? setting = await settingsRepository.FirstOrDefaultAsync(ct); if (setting is null) { diff --git a/PyroFetes/Specifications/Settings/GetSettingByIdSpec.cs b/PyroFetes/Specifications/Settings/GetSettingByIdSpec.cs deleted file mode 100644 index fb919a8..0000000 --- a/PyroFetes/Specifications/Settings/GetSettingByIdSpec.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Ardalis.Specification; -using PyroFetes.Models; - -namespace PyroFetes.Specifications.Settings; - -public sealed class GetSettingByIdSpec : SingleResultSpecification -{ - public GetSettingByIdSpec(int settingId) - { - Query - .Where(setting => setting.Id == settingId); - } -} \ No newline at end of file