fix paper controller

This commit is contained in:
Anton Romanov 2018-05-05 00:39:18 +04:00
parent d8fa601103
commit 7d286c0d76
4 changed files with 28 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Date;
import static java.nio.charset.StandardCharsets.UTF_8;
@ -29,6 +30,7 @@ public class FileService {
File file = new File();
file.setData(getTmpFile(tmpFileName));
file.setName(getTmpFileName(tmpFileName));
file.setCreateDate(new Date());
return fileRepository.save(file);
}

View File

@ -24,7 +24,7 @@ public class PaperController {
}
@GetMapping("/papers")
public Response<List<Paper>> getPapers() {
public Response<List<PaperDto>> getPapers() {
return new Response<>(paperService.findAll());
}

View File

@ -13,6 +13,9 @@ public class PaperDto {
private final String comment;
private final Boolean locked;
private final String tmpFileName;
private final Integer fileId;
private final String fileName;
private final Date fileCreateDate;
@JsonCreator
public PaperDto(@JsonProperty("title") String title,
@ -29,6 +32,9 @@ public class PaperDto {
this.comment = comment;
this.locked = locked;
this.tmpFileName = tmpFileName;
this.fileId = null;
this.fileName = null;
this.fileCreateDate = null;
}
public PaperDto(Paper paper) {
@ -39,6 +45,9 @@ public class PaperDto {
this.comment = paper.getComment();
this.locked = paper.getLocked();
this.tmpFileName = null;
this.fileId = paper.getFile() == null ? null : paper.getFile().getId();
this.fileName = paper.getFile() == null ? null : paper.getFile().getName();
this.fileCreateDate = paper.getFile() == null ? null : paper.getFile().getCreateDate();
}
public String getTitle() {
@ -68,4 +77,16 @@ public class PaperDto {
public String getTmpFileName() {
return tmpFileName;
}
public Integer getFileId() {
return fileId;
}
public String getFileName() {
return fileName;
}
public Date getFileCreateDate() {
return fileCreateDate;
}
}

View File

@ -12,6 +12,8 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import static ru.ulstu.core.util.StreamApiUtils.convert;
@Service
public class PaperService {
@ -24,8 +26,8 @@ public class PaperService {
this.fileService = fileService;
}
public List<Paper> findAll() {
return paperRepository.findAll();
public List<PaperDto> findAll() {
return convert(paperRepository.findAll(), PaperDto::new);
}
@Transactional