|
1
|
|
|
package com.osomapps.pt.reportphoto; |
|
2
|
|
|
|
|
3
|
|
|
import java.io.IOException; |
|
4
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
5
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
6
|
|
|
import org.springframework.util.FastByteArrayOutputStream; |
|
7
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
8
|
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
9
|
|
|
import org.springframework.web.bind.annotation.RequestHeader; |
|
10
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
11
|
|
|
import org.springframework.web.bind.annotation.ResponseBody; |
|
12
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
13
|
|
|
|
|
14
|
|
|
@RestController |
|
15
|
|
|
@RequestMapping("api/v1/report-photo-file") |
|
16
|
|
|
class ReportPhotoFileResource { |
|
17
|
|
|
|
|
18
|
|
|
private final ReportPhotoFileService reportPhotoFileService; |
|
19
|
|
|
|
|
20
|
|
|
@Autowired |
|
21
|
|
|
ReportPhotoFileResource(ReportPhotoFileService reportPhotoFileService) { |
|
22
|
|
|
this.reportPhotoFileService = reportPhotoFileService; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
@GetMapping("{id}/{fileName}") |
|
26
|
|
|
@ResponseBody |
|
27
|
|
|
void findOne( |
|
28
|
|
|
@RequestHeader(value = "X-Token") String token, |
|
29
|
|
|
@PathVariable Long id, |
|
30
|
|
|
@PathVariable String fileName, |
|
31
|
|
|
HttpServletResponse response) |
|
32
|
|
|
throws IOException { |
|
33
|
|
|
try (FastByteArrayOutputStream outputStream = new FastByteArrayOutputStream()) { |
|
34
|
|
|
final ReportPhotoFileDTO reportPhotoFileDTO = |
|
35
|
|
|
reportPhotoFileService.findOne(token, id, fileName, outputStream); |
|
36
|
|
|
response.setContentType(reportPhotoFileDTO.getFileType()); |
|
37
|
|
|
outputStream.writeTo(response.getOutputStream()); |
|
38
|
|
|
response.getOutputStream().close(); |
|
39
|
|
|
outputStream.reset(); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|