mirror of https://github.com/bvn13/ADaStor.git
replace entity with dto
parent
9a6a3cff37
commit
e4cc811af9
|
@ -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> stortion = stortionService.findStortion(uuid);
|
||||
Optional<StortionDto> 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");
|
||||
|
|
|
@ -53,16 +53,16 @@ public class StortionService {
|
|||
this.diskFreeSpaceChecker = diskFreeSpaceChecker;
|
||||
}
|
||||
|
||||
public Optional<Stortion> findStortion(String uuid) {
|
||||
return stortionRepository.findById(uuid);
|
||||
public Optional<StortionDto> 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;
|
||||
|
|
Loading…
Reference in New Issue