Total Complexity | 2 |
Total Lines | 28 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | package com.osomapps.pt.admin.user; |
||
13 | @RestController |
||
14 | @RequestMapping("api/v1/admin/user-program-file") |
||
15 | class AdminUserProgramFileResource { |
||
16 | |||
17 | private final AdminUserProgramFileService userProgramFileService; |
||
18 | |||
19 | @Autowired |
||
20 | AdminUserProgramFileResource(AdminUserProgramFileService userProgramFileService) { |
||
21 | this.userProgramFileService = userProgramFileService; |
||
22 | } |
||
23 | |||
24 | @GetMapping(value = "{id}/{fileName}") |
||
25 | @ResponseBody |
||
26 | Object findOne( |
||
27 | @PathVariable Long id, @PathVariable String fileName, HttpServletResponse response) |
||
28 | throws IOException { |
||
29 | try (FastByteArrayOutputStream outputStream = new FastByteArrayOutputStream()) { |
||
30 | final ProgramResponseDTO programResponseDTO = |
||
31 | userProgramFileService.createXlsx(id, outputStream); |
||
32 | response.setContentType(programResponseDTO.getFileType()); |
||
33 | response.setHeader( |
||
34 | "Content-disposition", |
||
35 | "attachment; filename=" + programResponseDTO.getFileName()); |
||
36 | outputStream.writeTo(response.getOutputStream()); |
||
37 | response.getOutputStream().close(); |
||
38 | outputStream.reset(); |
||
39 | } |
||
40 | return null; |
||
41 | } |
||
43 |