Fixed error with setting during conversion of base64
This commit is contained in:
@@ -2,6 +2,5 @@ namespace PyroFetes.DTO.SettingDTO.Request;
|
|||||||
|
|
||||||
public class PatchSettingElectronicSignatureDto
|
public class PatchSettingElectronicSignatureDto
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
|
||||||
public IFormFile? ElectronicSignature { get; set; }
|
public IFormFile? ElectronicSignature { get; set; }
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,5 @@ namespace PyroFetes.DTO.SettingDTO.Request;
|
|||||||
|
|
||||||
public class PatchSettingLogoDto
|
public class PatchSettingLogoDto
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
|
||||||
public IFormFile? Logo { get; set; }
|
public IFormFile? Logo { get; set; }
|
||||||
}
|
}
|
||||||
@@ -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<CreateSettingDto>
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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<DeleteSettingRequest>
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,28 +2,20 @@
|
|||||||
using PyroFetes.DTO.SettingDTO.Response;
|
using PyroFetes.DTO.SettingDTO.Response;
|
||||||
using PyroFetes.Models;
|
using PyroFetes.Models;
|
||||||
using PyroFetes.Repositories;
|
using PyroFetes.Repositories;
|
||||||
using PyroFetes.Specifications.Settings;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Settings;
|
namespace PyroFetes.Endpoints.Settings;
|
||||||
|
|
||||||
public class GetSettingRequest
|
public class GetSettingEndpoint(SettingsRepository settingsRepository, AutoMapper.IMapper mapper) : EndpointWithoutRequest<GetSettingDto>
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetSettingEndpoint(
|
|
||||||
SettingsRepository settingsRepository,
|
|
||||||
AutoMapper.IMapper mapper) : Endpoint<GetSettingRequest, GetSettingDto>
|
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/settings/{@Id}", x => new { x.Id });
|
Get("/settings/");
|
||||||
AllowAnonymous();
|
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)
|
if (setting is null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
using PyroFetes.DTO.SettingDTO.Request;
|
using PyroFetes.DTO.SettingDTO.Request;
|
||||||
using PyroFetes.Models;
|
using PyroFetes.Models;
|
||||||
using PyroFetes.Repositories;
|
using PyroFetes.Repositories;
|
||||||
using PyroFetes.Specifications.Settings;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Settings;
|
namespace PyroFetes.Endpoints.Settings;
|
||||||
|
|
||||||
@@ -10,13 +9,14 @@ public class PatchSettingElectronicSignatureEndpoint(SettingsRepository settings
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Patch("/settings/{@Id}/ElectronicSignature", x => new { x.Id });
|
Patch("/settings/electronicSignature");
|
||||||
|
AllowFormData();
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(PatchSettingElectronicSignatureDto req, CancellationToken ct)
|
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)
|
if (setting is null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
using PyroFetes.DTO.SettingDTO.Request;
|
using PyroFetes.DTO.SettingDTO.Request;
|
||||||
using PyroFetes.Models;
|
using PyroFetes.Models;
|
||||||
using PyroFetes.Repositories;
|
using PyroFetes.Repositories;
|
||||||
using PyroFetes.Specifications.Settings;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Settings;
|
namespace PyroFetes.Endpoints.Settings;
|
||||||
|
|
||||||
@@ -10,13 +9,14 @@ public class PatchSettingLogoEndpoint(SettingsRepository settingsRepository) : E
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Patch("/settings/{@Id}/logo", x => new { x.Id });
|
Patch("/settings/logo");
|
||||||
|
AllowFormData();
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(PatchSettingLogoDto req, CancellationToken ct)
|
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)
|
if (setting is null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
using Ardalis.Specification;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Specifications.Settings;
|
|
||||||
|
|
||||||
public sealed class GetSettingByIdSpec : SingleResultSpecification<Setting>
|
|
||||||
{
|
|
||||||
public GetSettingByIdSpec(int settingId)
|
|
||||||
{
|
|
||||||
Query
|
|
||||||
.Where(setting => setting.Id == settingId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user