AI Coding · Medium
Review this AI-generated endpoint for downloading invoices.
AI CodingSecurity & Supply ChainStaff
java
@GetMapping("/invoices/{id}/pdf")
@PreAuthorize("isAuthenticated()")
public ResponseEntity<byte[]> download(@PathVariable long id) {
Invoice invoice = invoiceRepository.findById(id).orElseThrow();
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_PDF)
.body(pdfRenderer.render(invoice));
}