#13 rename 'deleted', move creating fileDto to service

This commit is contained in:
Семенова Мария 2019-03-22 09:32:21 +04:00
parent c702e2abb4
commit 5da9de1bab
5 changed files with 22 additions and 17 deletions

View File

@ -53,9 +53,6 @@ public class FileController {
@PostMapping("/uploadTmpFile") @PostMapping("/uploadTmpFile")
public Response<FileDataDto> upload(@RequestParam("file") MultipartFile multipartFile) throws IOException { public Response<FileDataDto> upload(@RequestParam("file") MultipartFile multipartFile) throws IOException {
FileDataDto fileDataDto = new FileDataDto(); return new Response(fileService.createFromMultipartFile(multipartFile));
fileDataDto.setFileName(multipartFile.getOriginalFilename());
fileDataDto.setTmpFileName(fileService.uploadToTmpDir(multipartFile));
return new Response(fileDataDto);
} }
} }

View File

@ -9,7 +9,7 @@ public class FileDataDto {
private String fileName; private String fileName;
private String tmpFileName; private String tmpFileName;
private boolean deleteFlag; private boolean deleted;
public FileDataDto() { public FileDataDto() {
} }
@ -30,6 +30,10 @@ public class FileDataDto {
this.name = fileData.getName(); this.name = fileData.getName();
} }
public FileDataDto(String fileName, String tmpFileName) {
this.fileName = fileName;
this.tmpFileName = tmpFileName;
}
public Integer getId() { public Integer getId() {
return id; return id;
} }
@ -62,12 +66,12 @@ public class FileDataDto {
this.tmpFileName = tmpFileName; this.tmpFileName = tmpFileName;
} }
public boolean isDeleteFlag() { public boolean isDeleted() {
return deleteFlag; return deleted;
} }
public void setDeleteFlag(boolean deleteFlag) { public void setDeleted(boolean deleted) {
this.deleteFlag = deleteFlag; this.deleted = deleted;
} }
} }

View File

@ -119,4 +119,8 @@ public class FileService {
FileData file = fileRepository.findOne(fileId); FileData file = fileRepository.findOne(fileId);
fileRepository.delete(file); fileRepository.delete(file);
} }
public FileDataDto createFromMultipartFile(MultipartFile multipartFile) throws IOException {
return new FileDataDto(multipartFile.getOriginalFilename(), uploadToTmpDir(multipartFile));
}
} }

View File

@ -90,7 +90,7 @@ public class PaperService {
paper.setTitle(paperDto.getTitle()); paper.setTitle(paperDto.getTitle());
paper.setUpdateDate(new Date()); paper.setUpdateDate(new Date());
paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines())); 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(); paper.getAuthors().clear();
if (paperDto.getAuthorIds() != null && !paperDto.getAuthorIds().isEmpty()) { if (paperDto.getAuthorIds() != null && !paperDto.getAuthorIds().isEmpty()) {
paperDto.getAuthorIds().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds))); paperDto.getAuthorIds().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds)));
@ -104,7 +104,7 @@ public class PaperService {
Paper.PaperStatus oldStatus = paper.getStatus(); Paper.PaperStatus oldStatus = paper.getStatus();
Set<User> oldAuthors = new HashSet<>(paper.getAuthors()); Set<User> 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()); fileService.delete(file.getId());
} }

View File

@ -96,14 +96,14 @@
<label>Файлы:</label> <label>Файлы:</label>
<th:block th:each="file, rowStat : *{files}"> <th:block th:each="file, rowStat : *{files}">
<div class="row" th:id="|files${rowStat.index}|" <div class="row" th:id="|files${rowStat.index}|"
th:style="${file.deleteFlag} ? 'display: none;' :''"> th:style="${file.deleted} ? 'display: none;' :''">
<input type="hidden" th:field="*{files[__${rowStat.index}__].id}"/> <input type="hidden" th:field="*{files[__${rowStat.index}__].id}"/>
<input type="hidden" th:field="*{files[__${rowStat.index}__].deleteFlag}"/> <input type="hidden" th:field="*{files[__${rowStat.index}__].deleted}"/>
<input type="hidden" th:field="*{files[__${rowStat.index}__].name}"/> <input type="hidden" th:field="*{files[__${rowStat.index}__].name}"/>
<input type="hidden" th:field="*{files[__${rowStat.index}__].tmpFileName}"/> <input type="hidden" th:field="*{files[__${rowStat.index}__].tmpFileName}"/>
<div class="col-2"> <div class="col-2">
<a class="btn btn-danger float-right" <a class="btn btn-danger float-right"
th:onclick="|$('#files${rowStat.index}\\.deleteFlag').val('true'); $('#files${rowStat.index}').hide(); |"> th:onclick="|$('#files${rowStat.index}\\.deleted').val('true'); $('#files${rowStat.index}').hide(); |">
<span aria-hidden="true"><i class="fa fa-times"/></span> <span aria-hidden="true"><i class="fa fa-times"/></span>
</a> </a>
</div> </div>
@ -222,9 +222,9 @@
var flagInput = $("<input/>") var flagInput = $("<input/>")
.attr("type", "hidden") .attr("type", "hidden")
.attr("id", "files" + fileNumber + ".deleteFlag") .attr("id", "files" + fileNumber + ".deleted")
.attr("value", "false") .attr("value", "false")
.attr("name", "files[" + fileNumber + "].deleteFlag"); .attr("name", "files[" + fileNumber + "].deleted");
newFileRow.append(flagInput); newFileRow.append(flagInput);
var nameInput = $("<input/>") var nameInput = $("<input/>")
@ -246,7 +246,7 @@
var nextA = $("<a/>") var nextA = $("<a/>")
.addClass("btn btn-danger float-right") .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(($("<span/>").attr("aria-hidden", "true")).append($("<i/>").addClass("fa fa-times"))) .append(($("<span/>").attr("aria-hidden", "true")).append($("<i/>").addClass("fa fa-times")))
; ;
nextDiv.append(nextA) nextDiv.append(nextA)