Updated code
This commit is contained in:
@@ -131,6 +131,22 @@ public interface ApplicationApi {
|
||||
@Parameter(description = "The application id", required = true) @PathVariable("applicationId") Long applicationId,
|
||||
@Parameter(description = "status", required = true)@RequestParam(value = "status", required = true) ApplicationStatusTypeEnum status);
|
||||
|
||||
@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}/download-pdf",
|
||||
produces = { "application/pdf" })
|
||||
public ResponseEntity<byte[]> generateApplicationPdf(
|
||||
HttpServletRequest request,
|
||||
@Parameter(description = "The application id", required = true)
|
||||
@PathVariable(value = "applicationId", required = true) Long applicationId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -13,11 +13,14 @@ import net.gepafin.tendermanagement.model.response.ApplicationResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.NextOrPreviousFormResponse;
|
||||
import net.gepafin.tendermanagement.model.util.Response;
|
||||
import net.gepafin.tendermanagement.service.ApplicationService;
|
||||
import net.gepafin.tendermanagement.service.PdfService;
|
||||
import net.gepafin.tendermanagement.web.rest.api.ApplicationApi;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -35,11 +38,15 @@ public class ApplicationApiController implements ApplicationApi {
|
||||
@Autowired
|
||||
private ApplicationService applicationService;
|
||||
|
||||
@Autowired
|
||||
private PdfService pdfService;
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<ApplicationResponseBean>> createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long applicationId, Long formId) {
|
||||
ApplicationResponseBean applicationResponseBean = applicationService.createApplication(request, applicationRequestBean, applicationId, formId);
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(new Response<>(applicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.APPLICATION_CREATED_SUCCESS_MSG))); }
|
||||
.body(new Response<>(applicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.APPLICATION_CREATED_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<ApplicationGetResponseBean>> getApplicationByFormId(HttpServletRequest request
|
||||
@@ -65,6 +72,7 @@ public class ApplicationApiController implements ApplicationApi {
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(new Response<>(applicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.APPLICATION_CREATED_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<List<ApplicationResponse>>> getAllApplications(HttpServletRequest request, Long callId, Long companyId) {
|
||||
List<ApplicationResponse> applications = applicationService.getAllApplications(request, callId, companyId);
|
||||
@@ -89,4 +97,19 @@ public class ApplicationApiController implements ApplicationApi {
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(applicationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.APPLICATION_STATUS_UPDATED_SUCCESSFULLY)));
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user