From e4cc811af92b388a5e2c3481aa675d1c60aa6f28 Mon Sep 17 00:00:00 2001 From: bvn13 Date: Fri, 19 Apr 2019 21:39:20 +0300 Subject: [PATCH] replace entity with dto --- .../ru/bvn13/adastor/web/controllers/ViewController.java | 6 +++--- .../ru/bvn13/adastor/web/services/StortionService.java | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/ru/bvn13/adastor/web/controllers/ViewController.java b/src/main/java/ru/bvn13/adastor/web/controllers/ViewController.java index 67e4073..f94b578 100644 --- a/src/main/java/ru/bvn13/adastor/web/controllers/ViewController.java +++ b/src/main/java/ru/bvn13/adastor/web/controllers/ViewController.java @@ -4,7 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; -import ru.bvn13.adastor.entities.Stortion; +import ru.bvn13.adastor.entities.dtos.StortionDto; import ru.bvn13.adastor.web.services.StortionService; import javax.servlet.http.HttpServletResponse; @@ -29,13 +29,13 @@ public class ViewController { @GetMapping("/v/{uuid}") public void getStortion(@PathVariable("uuid") String uuid, HttpServletResponse response) throws IOException { - Optional stortion = stortionService.findStortion(uuid); + Optional stortion = stortionService.findStortion(uuid); if (stortion.isPresent()) { try(BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream())) { InputStream is = stortionService.getInputStream(stortion.get()); is.transferTo(bos); } catch (FileNotFoundException e) { - response.sendError(403, "not found"); + response.sendError(404, "not found"); } } else { response.sendRedirect("/notfound"); diff --git a/src/main/java/ru/bvn13/adastor/web/services/StortionService.java b/src/main/java/ru/bvn13/adastor/web/services/StortionService.java index 94efb41..1184ce4 100644 --- a/src/main/java/ru/bvn13/adastor/web/services/StortionService.java +++ b/src/main/java/ru/bvn13/adastor/web/services/StortionService.java @@ -53,16 +53,16 @@ public class StortionService { this.diskFreeSpaceChecker = diskFreeSpaceChecker; } - public Optional findStortion(String uuid) { - return stortionRepository.findById(uuid); + public Optional findStortion(String uuid) { + return stortionRepository.findById(uuid).map(this::convertToDto); } - public String getPath(Stortion stortion) { + public String getPath(StortionDto stortion) { String storagePath = config.getStoragePath(); return storagePath + stortion.getPath(); } - public InputStream getInputStream(Stortion stortion) throws FileNotFoundException { + public InputStream getInputStream(StortionDto stortion) throws FileNotFoundException { String path = getPath(stortion); InputStream targetStream = new DataInputStream(new FileInputStream(path)); return targetStream;