From c702e2abb49a9243f5f6b3f8209b8a94931b85da 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: Thu, 21 Mar 2019 18:26:28 +0400 Subject: [PATCH] #13 fileDataDto instead of Object[] --- .../java/ru/ulstu/file/FileController.java | 15 ++++++++++--- src/main/java/ru/ulstu/paper/model/Paper.java | 22 +++++++++++++++++-- .../ru/ulstu/paper/service/PaperService.java | 13 +++++++++-- .../resources/templates/papers/paper.html | 11 +++++----- 4 files changed, 48 insertions(+), 13 deletions(-) diff --git a/src/main/java/ru/ulstu/file/FileController.java b/src/main/java/ru/ulstu/file/FileController.java index f68b820..591c23d 100644 --- a/src/main/java/ru/ulstu/file/FileController.java +++ b/src/main/java/ru/ulstu/file/FileController.java @@ -3,11 +3,17 @@ package ru.ulstu.file; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import ru.ulstu.configuration.Constants; import ru.ulstu.core.model.response.Response; import ru.ulstu.file.model.FileData; +import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.service.FileService; import java.io.IOException; @@ -46,7 +52,10 @@ public class FileController { } @PostMapping("/uploadTmpFile") - public Response upload(@RequestParam("file") MultipartFile multipartFile) throws IOException { - return new Response(new Object[]{fileService.uploadToTmpDir(multipartFile), multipartFile.getOriginalFilename()}); + 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); } } diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index f98b54b..b2f8327 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -9,8 +9,26 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; import ru.ulstu.user.model.User; -import javax.persistence.*; -import java.util.*; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToMany; +import javax.persistence.OneToMany; +import javax.persistence.OrderBy; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; + @Entity public class Paper extends BaseEntity implements UserContainer { diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 851a21b..932735d 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -15,12 +15,21 @@ import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; import java.io.IOException; -import java.util.*; +import java.util.Arrays; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import java.util.stream.Collectors; import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; -import static ru.ulstu.paper.model.Paper.PaperStatus.*; +import static ru.ulstu.paper.model.Paper.PaperStatus.ATTENTION; +import static ru.ulstu.paper.model.Paper.PaperStatus.COMPLETED; +import static ru.ulstu.paper.model.Paper.PaperStatus.DRAFT; +import static ru.ulstu.paper.model.Paper.PaperStatus.FAILED; +import static ru.ulstu.paper.model.Paper.PaperStatus.ON_PREPARATION; + @Service public class PaperService { diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index 1daec46..3dafd90 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -206,8 +206,7 @@ $('.selectpicker').selectpicker(); }); /*]]>*/ - function addNewFile(fileNames) { - var filesList = $("#files-list"); + function addNewFile(fileDto) { var fileNumber = $("#files-list div.row").length; var newFileRow = $("
") @@ -231,14 +230,14 @@ var nameInput = $("") .attr("type", "hidden") .attr("id", "files" + fileNumber + ".name") - .attr("value", fileNames[1]) + .attr("value", fileDto.fileName) .attr("name", "files[" + fileNumber + "].name"); newFileRow.append(nameInput); var tmpFileNameInput = $("") .attr("type", "hidden") .attr("id", "files" + fileNumber + ".tmpFileName") - .attr("value", fileNames[0]) + .attr("value", fileDto.tmpFileName) .attr("name", "files[" + fileNumber + "].tmpFileName"); newFileRow.append(tmpFileNameInput); @@ -255,9 +254,9 @@ var nameDiv = $("
") .addClass("col-10") - .append($("").text(fileNames[1]) + .append($("").text(fileDto.fileName) .attr("href", 'javascript:void(0)') - .attr("onclick", "downloadFile('" + fileNames[0] + "',null,'" + fileNames[1] + "')")); + .attr("onclick", "downloadFile('" + fileDto.tmpFileName + "',null,'" + fileDto.fileName + "')")); newFileRow.append(nameDiv); $("#files-list").append(newFileRow);