From 5da9de1bab4d05d448bf2a37993b29fa76615f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=9C?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=8F?= Date: Fri, 22 Mar 2019 09:32:21 +0400 Subject: [PATCH] #13 rename 'deleted', move creating fileDto to service --- src/main/java/ru/ulstu/file/FileController.java | 5 +---- src/main/java/ru/ulstu/file/model/FileDataDto.java | 14 +++++++++----- .../java/ru/ulstu/file/service/FileService.java | 4 ++++ .../java/ru/ulstu/paper/service/PaperService.java | 4 ++-- src/main/resources/templates/papers/paper.html | 12 ++++++------ 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/main/java/ru/ulstu/file/FileController.java b/src/main/java/ru/ulstu/file/FileController.java index 591c23d..ac08ac1 100644 --- a/src/main/java/ru/ulstu/file/FileController.java +++ b/src/main/java/ru/ulstu/file/FileController.java @@ -53,9 +53,6 @@ public class FileController { @PostMapping("/uploadTmpFile") public Response upload(@RequestParam("file") MultipartFile multipartFile) throws IOException { - FileDataDto fileDataDto = new FileDataDto(); - fileDataDto.setFileName(multipartFile.getOriginalFilename()); - fileDataDto.setTmpFileName(fileService.uploadToTmpDir(multipartFile)); - return new Response(fileDataDto); + return new Response(fileService.createFromMultipartFile(multipartFile)); } } diff --git a/src/main/java/ru/ulstu/file/model/FileDataDto.java b/src/main/java/ru/ulstu/file/model/FileDataDto.java index d117fe7..f99656c 100644 --- a/src/main/java/ru/ulstu/file/model/FileDataDto.java +++ b/src/main/java/ru/ulstu/file/model/FileDataDto.java @@ -9,7 +9,7 @@ public class FileDataDto { private String fileName; private String tmpFileName; - private boolean deleteFlag; + private boolean deleted; public FileDataDto() { } @@ -30,6 +30,10 @@ public class FileDataDto { this.name = fileData.getName(); } + public FileDataDto(String fileName, String tmpFileName) { + this.fileName = fileName; + this.tmpFileName = tmpFileName; + } public Integer getId() { return id; } @@ -62,12 +66,12 @@ public class FileDataDto { this.tmpFileName = tmpFileName; } - public boolean isDeleteFlag() { - return deleteFlag; + public boolean isDeleted() { + return deleted; } - public void setDeleteFlag(boolean deleteFlag) { - this.deleteFlag = deleteFlag; + public void setDeleted(boolean deleted) { + this.deleted = deleted; } } diff --git a/src/main/java/ru/ulstu/file/service/FileService.java b/src/main/java/ru/ulstu/file/service/FileService.java index 68d0b35..7c40b60 100644 --- a/src/main/java/ru/ulstu/file/service/FileService.java +++ b/src/main/java/ru/ulstu/file/service/FileService.java @@ -119,4 +119,8 @@ public class FileService { FileData file = fileRepository.findOne(fileId); fileRepository.delete(file); } + + public FileDataDto createFromMultipartFile(MultipartFile multipartFile) throws IOException { + return new FileDataDto(multipartFile.getOriginalFilename(), uploadToTmpDir(multipartFile)); + } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 932735d..7c5df22 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -90,7 +90,7 @@ public class PaperService { paper.setTitle(paperDto.getTitle()); paper.setUpdateDate(new Date()); paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines())); - paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream().filter(f -> f.isDeleteFlag() == false).collect(Collectors.toList()))); + paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream().filter(f -> !f.isDeleted()).collect(Collectors.toList()))); paper.getAuthors().clear(); if (paperDto.getAuthorIds() != null && !paperDto.getAuthorIds().isEmpty()) { paperDto.getAuthorIds().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds))); @@ -104,7 +104,7 @@ public class PaperService { Paper.PaperStatus oldStatus = paper.getStatus(); Set oldAuthors = new HashSet<>(paper.getAuthors()); - for (FileDataDto file : paperDto.getFiles().stream().filter(f -> f.isDeleteFlag() == true && f.getId() != null).collect(Collectors.toList())) { + for (FileDataDto file : paperDto.getFiles().stream().filter(f -> f.isDeleted() && f.getId() != null).collect(Collectors.toList())) { fileService.delete(file.getId()); } diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index 3dafd90..a0b11f1 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -96,14 +96,14 @@
+ th:style="${file.deleted} ? 'display: none;' :''"> - + @@ -222,9 +222,9 @@ var flagInput = $("") .attr("type", "hidden") - .attr("id", "files" + fileNumber + ".deleteFlag") + .attr("id", "files" + fileNumber + ".deleted") .attr("value", "false") - .attr("name", "files[" + fileNumber + "].deleteFlag"); + .attr("name", "files[" + fileNumber + "].deleted"); newFileRow.append(flagInput); var nameInput = $("") @@ -246,7 +246,7 @@ var nextA = $("") .addClass("btn btn-danger float-right") - .attr("onclick", "$('#files" + fileNumber + "\\\\.deleteFlag').val('true'); $('#files" + fileNumber + "').hide();") + .attr("onclick", "$('#files" + fileNumber + "\\\\.deleted').val('true'); $('#files" + fileNumber + "').hide();") .append(($("").attr("aria-hidden", "true")).append($("").addClass("fa fa-times"))) ; nextDiv.append(nextA)