Done ticket

This commit is contained in:
nisha
2024-10-12 15:43:38 +05:30
parent 90aae05fa4
commit b6f16d388e
9 changed files with 833 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
package net.gepafin.tendermanagement.web.rest.api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@Validated
public interface PdfApi {
@Operation(summary = "API to generate PDF for an application",
responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(mediaType = "application/pdf")),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
})
@PostMapping(value = "/{applicationId}/generate-pdf",
produces = { "application/pdf" })
public ResponseEntity<byte[]> generateApplicationPdf(
HttpServletRequest request,
@Parameter(description = "The application id", required = true)
@PathVariable(value = "applicationId", required = true) Long applicationId);
}

View File

@@ -0,0 +1,40 @@
package net.gepafin.tendermanagement.web.rest.api.impl;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.dao.RoundedCorners;
import net.gepafin.tendermanagement.service.PdfService;
import net.gepafin.tendermanagement.web.rest.api.PdfApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@RestController
public class PdfController implements PdfApi {
@Autowired
private PdfService pdfService;
@Override
public ResponseEntity<byte[]> generateApplicationPdf(HttpServletRequest request, Long applicationId) {
byte[] pdfBytes =pdfService.generatePdf(request,applicationId);
// Prepare headers for downloading the PDF
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Disposition", "attachment; filename=bando-preview.pdf");
// Return the PDF as a response
return ResponseEntity.ok()
.headers(headers)
.contentType(MediaType.APPLICATION_PDF)
.body(pdfBytes);
}
}