change response in endpoint to generate pdf

This commit is contained in:
2025-12-04 16:38:27 +01:00
parent 6a20676b32
commit 17978e7c19
4 changed files with 15 additions and 7 deletions

View File

@@ -1,4 +1,5 @@
using FastEndpoints; using System.Net.Mime;
using FastEndpoints;
using PyroFetes.DTO.DeliveryNote.Request; using PyroFetes.DTO.DeliveryNote.Request;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
@@ -11,12 +12,13 @@ namespace PyroFetes.Endpoints.DeliveryNotes;
public class GetDeliveryNotePdfEndpoint( public class GetDeliveryNotePdfEndpoint(
DeliveryNotesRepository deliveryNotesRepository, DeliveryNotesRepository deliveryNotesRepository,
IDeliveryNotePdfService deliveryNotePdfService) IDeliveryNotePdfService deliveryNotePdfService)
: Endpoint<GetDeliveryNotePdfDto> : Endpoint<GetDeliveryNotePdfDto, byte[]>
{ {
public override void Configure() public override void Configure()
{ {
Get("/deliveryNotes/{@Id}/pdf", x => new {x.Id}); Get("/deliveryNotes/{@Id}/pdf", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf));
} }
public override async Task HandleAsync(GetDeliveryNotePdfDto req, CancellationToken ct) public override async Task HandleAsync(GetDeliveryNotePdfDto req, CancellationToken ct)

View File

@@ -1,4 +1,5 @@
using FastEndpoints; using System.Net.Mime;
using FastEndpoints;
using PyroFetes.DTO.PurchaseOrder.Request; using PyroFetes.DTO.PurchaseOrder.Request;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
@@ -9,12 +10,13 @@ namespace PyroFetes.Endpoints.PurchaseOrders;
public class GetPurchaseOrderPdfEndpoint( public class GetPurchaseOrderPdfEndpoint(
PurchaseOrdersRepository purchaseOrdersRepository, PurchaseOrdersRepository purchaseOrdersRepository,
IPurchaseOrderPdfService purchaseOrderPdfService) IPurchaseOrderPdfService purchaseOrderPdfService)
: Endpoint<GetPurchaseOrderPdfDto> : Endpoint<GetPurchaseOrderPdfDto, byte[]>
{ {
public override void Configure() public override void Configure()
{ {
Get("/purchaseOrders/{@Id}/pdf", x => new {x.Id}); Get("/purchaseOrders/{@Id}/pdf", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf));
} }
public override async Task HandleAsync(GetPurchaseOrderPdfDto req, CancellationToken ct) public override async Task HandleAsync(GetPurchaseOrderPdfDto req, CancellationToken ct)

View File

@@ -1,4 +1,5 @@
using FastEndpoints; using System.Net.Mime;
using FastEndpoints;
using PyroFetes.DTO.Quotation.Request; using PyroFetes.DTO.Quotation.Request;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
@@ -10,12 +11,13 @@ namespace PyroFetes.Endpoints.Quotations;
public class GetQuotationPdfEndpoint( public class GetQuotationPdfEndpoint(
QuotationsRepository quotationRepository, QuotationsRepository quotationRepository,
IQuotationPdfService quotationPdfService) IQuotationPdfService quotationPdfService)
: Endpoint<GetQuotationPdfDto> : Endpoint<GetQuotationPdfDto, byte[]>
{ {
public override void Configure() public override void Configure()
{ {
Get("/quotations/{@Id}/pdf", x => new {x.Id}); Get("/quotations/{@Id}/pdf", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf));
} }
public override async Task HandleAsync(GetQuotationPdfDto req, CancellationToken ct) public override async Task HandleAsync(GetQuotationPdfDto req, CancellationToken ct)

View File

@@ -4,6 +4,7 @@ using PyroFetes;
using FastEndpoints; using FastEndpoints;
using FastEndpoints.Swagger; using FastEndpoints.Swagger;
using FastEndpoints.Security; using FastEndpoints.Security;
using Microsoft.Net.Http.Headers;
using PyroFetes.MappingProfiles; using PyroFetes.MappingProfiles;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Services.Pdf; using PyroFetes.Services.Pdf;
@@ -30,7 +31,8 @@ builder.Services
policyBuilder policyBuilder
.WithOrigins("http://localhost:4200") .WithOrigins("http://localhost:4200")
.WithMethods("GET", "POST", "PUT", "DELETE", "PATCH") .WithMethods("GET", "POST", "PUT", "DELETE", "PATCH")
.AllowAnyHeader(); .AllowAnyHeader()
.WithExposedHeaders(HeaderNames.ContentDisposition);
}); });
}); });