Skip to content

Commit

Permalink
fix: taking object instead of a string
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-urner committed Aug 15, 2024
1 parent ffd6985 commit 947e348
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
<version>3.2.1</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>

<!-- JWT Tokens -->

<dependency>
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/dev/urner/volodb/rest/DocumentRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.val;

import java.io.IOException;
import java.io.InputStream;
import java.net.URLConnection;
import java.util.Base64;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
Expand All @@ -29,6 +33,8 @@
@RequiredArgsConstructor
public class DocumentRestController {

private static final Logger logger = LoggerFactory.getLogger(DocumentRestController.class);

private final FileService fileService;
private final DocumentService documentService;

Expand Down Expand Up @@ -62,9 +68,19 @@ public ResponseEntity<String> getTestMethod(@PathVariable("templateId") int temp
}

@PostMapping("")
public ResponseEntity<String> createPdf(@RequestBody String htmlContent)
public ResponseEntity<String> createPdf(@RequestBody Map<String, Object> data)
throws IOException {

String htmlContent = "";

for (Map.Entry<String, Object> entry : data.entrySet()) {
System.out.println(entry.getKey() + ":" + entry.getValue());
if (entry.getKey().toLowerCase() == "html") {
htmlContent = entry.getValue().toString();
logger.info(htmlContent);
}
}

byte[] pdfBytes = documentService.generatePdfFromHtml(htmlContent);

// Encode the PDF in Base64
Expand Down

0 comments on commit 947e348

Please sign in to comment.