#13 fileDataDto instead of Object[]

This commit is contained in:
Семенова Мария 2019-03-21 18:26:28 +04:00
parent 3c068df201
commit c702e2abb4
4 changed files with 48 additions and 13 deletions

View File

@ -3,11 +3,17 @@ package ru.ulstu.file;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; 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 org.springframework.web.multipart.MultipartFile;
import ru.ulstu.configuration.Constants; import ru.ulstu.configuration.Constants;
import ru.ulstu.core.model.response.Response; import ru.ulstu.core.model.response.Response;
import ru.ulstu.file.model.FileData; import ru.ulstu.file.model.FileData;
import ru.ulstu.file.model.FileDataDto;
import ru.ulstu.file.service.FileService; import ru.ulstu.file.service.FileService;
import java.io.IOException; import java.io.IOException;
@ -46,7 +52,10 @@ public class FileController {
} }
@PostMapping("/uploadTmpFile") @PostMapping("/uploadTmpFile")
public Response<Object[]> upload(@RequestParam("file") MultipartFile multipartFile) throws IOException { public Response<FileDataDto> upload(@RequestParam("file") MultipartFile multipartFile) throws IOException {
return new Response(new Object[]{fileService.uploadToTmpDir(multipartFile), multipartFile.getOriginalFilename()}); FileDataDto fileDataDto = new FileDataDto();
fileDataDto.setFileName(multipartFile.getOriginalFilename());
fileDataDto.setTmpFileName(fileService.uploadToTmpDir(multipartFile));
return new Response(fileDataDto);
} }
} }

View File

@ -9,8 +9,26 @@ import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.file.model.FileData; import ru.ulstu.file.model.FileData;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import javax.persistence.*; import javax.persistence.CascadeType;
import java.util.*; 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 @Entity
public class Paper extends BaseEntity implements UserContainer { public class Paper extends BaseEntity implements UserContainer {

View File

@ -15,12 +15,21 @@ import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService; import ru.ulstu.user.service.UserService;
import java.io.IOException; 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 java.util.stream.Collectors;
import static org.springframework.util.ObjectUtils.isEmpty; import static org.springframework.util.ObjectUtils.isEmpty;
import static ru.ulstu.core.util.StreamApiUtils.convert; 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 @Service
public class PaperService { public class PaperService {

View File

@ -206,8 +206,7 @@
$('.selectpicker').selectpicker(); $('.selectpicker').selectpicker();
}); });
/*]]>*/ /*]]>*/
function addNewFile(fileNames) { function addNewFile(fileDto) {
var filesList = $("#files-list");
var fileNumber = $("#files-list div.row").length; var fileNumber = $("#files-list div.row").length;
var newFileRow = $("<div/>") var newFileRow = $("<div/>")
@ -231,14 +230,14 @@
var nameInput = $("<input/>") var nameInput = $("<input/>")
.attr("type", "hidden") .attr("type", "hidden")
.attr("id", "files" + fileNumber + ".name") .attr("id", "files" + fileNumber + ".name")
.attr("value", fileNames[1]) .attr("value", fileDto.fileName)
.attr("name", "files[" + fileNumber + "].name"); .attr("name", "files[" + fileNumber + "].name");
newFileRow.append(nameInput); newFileRow.append(nameInput);
var tmpFileNameInput = $("<input/>") var tmpFileNameInput = $("<input/>")
.attr("type", "hidden") .attr("type", "hidden")
.attr("id", "files" + fileNumber + ".tmpFileName") .attr("id", "files" + fileNumber + ".tmpFileName")
.attr("value", fileNames[0]) .attr("value", fileDto.tmpFileName)
.attr("name", "files[" + fileNumber + "].tmpFileName"); .attr("name", "files[" + fileNumber + "].tmpFileName");
newFileRow.append(tmpFileNameInput); newFileRow.append(tmpFileNameInput);
@ -255,9 +254,9 @@
var nameDiv = $("<div/>") var nameDiv = $("<div/>")
.addClass("col-10") .addClass("col-10")
.append($("<a/>").text(fileNames[1]) .append($("<a/>").text(fileDto.fileName)
.attr("href", 'javascript:void(0)') .attr("href", 'javascript:void(0)')
.attr("onclick", "downloadFile('" + fileNames[0] + "',null,'" + fileNames[1] + "')")); .attr("onclick", "downloadFile('" + fileDto.tmpFileName + "',null,'" + fileDto.fileName + "')"));
newFileRow.append(nameDiv); newFileRow.append(nameDiv);
$("#files-list").append(newFileRow); $("#files-list").append(newFileRow);