Fixed error with setting during conversion of base64
This commit is contained in:
@@ -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.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<GetSettingRequest, GetSettingDto>
|
||||
public class GetSettingEndpoint(SettingsRepository settingsRepository, AutoMapper.IMapper mapper) : EndpointWithoutRequest<GetSettingDto>
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user