Skip to content

Commit

Permalink
Add some details to the screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis van Loon committed Oct 25, 2022
1 parent 3919b55 commit cab760c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ build/

### VS Code ###
.vscode/

.mvn/
mvnw*
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM eclipse-temurin:17-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
21 changes: 21 additions & 0 deletions src/main/java/com/dvl/adobesign/controller/ContactController.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package com.dvl.adobesign.controller;

import com.dvl.adobesign.model.Contract;
import com.dvl.adobesign.service.ContractService;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.io.ByteArrayInputStream;

@Controller
public class ContactController {

Expand All @@ -28,4 +37,16 @@ public String handleFileUpload(@RequestParam("file") MultipartFile file) {
contractService.storeContract(file);
return "redirect:/";
}

@GetMapping(value = "/download/{id}")
public ResponseEntity<InputStreamResource> downloadFile(@PathVariable String id) {
Contract contract = contractService.getContract(id);

HttpHeaders respHeaders = new HttpHeaders();
respHeaders.setContentType(MediaType.valueOf(contract.getFileType()));
respHeaders.setContentLength(contract.getData().length);
respHeaders.setContentDispositionFormData("attachment", contract.getFileName());

return new ResponseEntity<>(new InputStreamResource(new ByteArrayInputStream(contract.getData())), respHeaders, HttpStatus.OK);
}
}
41 changes: 29 additions & 12 deletions src/main/resources/templates/index.ftlh
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
<#import "/spring.ftl" as spring/>
<html>
<body>
Hello there, you currently have ${contracts?size} contracts
<html lang="en">
<body>
<div>Hello there, you currently have ${contracts?size} contracts</div>

<form name="upload" enctype="multipart/form-data" action="/contract" method="POST">
<p>
<div><input id="file" type="file" name="file"></div>
</p>
<p>
<input type="submit" value="Upload file">
</p>
</form>
</body>
<div>
<form name="upload" enctype="multipart/form-data" action="/contract" method="POST">
<input id="file" type="file" name="file">
<input type="submit" value="Upload file">
</form>
</div>

<div>
<table>
<tr>
<th>id</th>
<th>fileName</th>
<th>fileType</th>
<th>download</th>
</tr>
<#foreach contract in contracts>
<tr>
<td>${contract.id}</td>
<td>${contract.fileName}</td>
<td>${contract.fileType}</td>
<td><a href="download/${contract.id}">download</a></td>
</tr>
</#foreach>
</table>
</div>
</body>
</html>

0 comments on commit cab760c

Please sign in to comment.