#247 -- Fix paper dates

This commit is contained in:
Anton Romanov 2024-05-02 19:16:18 +04:00
parent 6dc88fdada
commit e6b4ed9f2c
5 changed files with 11 additions and 43 deletions

View File

@ -2,9 +2,6 @@ package ru.ulstu.paper.controller;
import io.swagger.v3.oas.annotations.Hidden;
import jakarta.validation.Valid;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.Errors;
@ -19,21 +16,16 @@ import ru.ulstu.paper.model.AutoCompleteData;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.model.PaperListDto;
import ru.ulstu.paper.model.ReferenceDto;
import ru.ulstu.paper.service.LatexService;
import ru.ulstu.paper.service.PaperService;
import ru.ulstu.user.model.User;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.stream.Collectors;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.springframework.util.StringUtils.isEmpty;
@Controller()
@RequestMapping(value = "/papers")
@ -76,7 +68,7 @@ public class PaperController {
}
@GetMapping("/paper")
public void getPapers(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
public void getPaper(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
if (id != null && id > 0) {
modelMap.put("paperDto", paperService.findOneDto(id));
} else {
@ -107,15 +99,6 @@ public class PaperController {
return "/papers/paper";
}
@PostMapping(value = "/paper", params = "addReference")
public String addReference(@Valid PaperDto paperDto, Errors errors) {
if (errors.hasErrors()) {
return "/papers/paper";
}
paperDto.getReferences().add(new ReferenceDto());
return "/papers/paper";
}
@ModelAttribute("allStatuses")
public List<Paper.PaperStatus> getPaperStatuses() {
return paperService.getPaperStatuses();
@ -140,29 +123,6 @@ public class PaperController {
return years;
}
@ModelAttribute("allFormatStandards")
public List<ReferenceDto.FormatStandard> getFormatStandards() {
return paperService.getFormatStandards();
}
@ModelAttribute("allReferenceTypes")
public List<ReferenceDto.ReferenceType> getReferenceTypes() {
return paperService.getReferenceTypes();
}
@PostMapping("/generatePdf")
public ResponseEntity<byte[]> getPdfFile(PaperDto paper) throws IOException, InterruptedException {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Disposition", "attachment; filename='" +
URLEncoder.encode(paper.getTitle() + ".pdf", UTF_8.toString()) + "'");
return new ResponseEntity<>(latexService.generatePdfFromLatexFile(paper), headers, HttpStatus.OK);
}
@PostMapping("/getFormattedReferences")
public ResponseEntity<String> getFormattedReferences(PaperDto paperDto) {
return new ResponseEntity<>(paperService.getFormattedReferences(paperDto), new HttpHeaders(), HttpStatus.OK);
}
@ModelAttribute("autocompleteData")
public AutoCompleteData getAutocompleteData() {
return paperService.getAutoCompleteData();
@ -170,7 +130,7 @@ public class PaperController {
private void filterEmptyDeadlines(PaperDto paperDto) {
paperDto.setDeadlines(paperDto.getDeadlines().stream()
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
.filter(dto -> dto.getDate() != null || !dto.getDescription().isEmpty())
.collect(Collectors.toList()));
}
}

View File

@ -17,6 +17,7 @@ import jakarta.persistence.TemporalType;
import jakarta.validation.constraints.NotBlank;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.springframework.format.annotation.DateTimeFormat;
import ru.ulstu.conference.model.Conference;
import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.core.model.EventSource;
@ -94,10 +95,12 @@ public class Paper extends BaseEntity implements UserActivity, EventSource {
@Column(name = "create_date")
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSXXX")
private Date createDate = new Date();
@Column(name = "update_date")
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSXXX")
private Date updateDate = new Date();
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)

View File

@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;
import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.file.model.FileDataDto;
@ -27,7 +28,9 @@ public class PaperDto {
private String title;
private Paper.PaperStatus status;
private Paper.PaperType type;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSXXX")
private Date createDate;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSXXX")
private Date updateDate;
@NotEmpty
private List<Deadline> deadlines = new ArrayList<>();

View File

@ -103,7 +103,7 @@ public class PaperService {
}
public PaperDto findOneDto(Integer id) {
return new PaperDto(paperRepository.getOne(id));
return new PaperDto(paperRepository.findById(id).orElseThrow());
}
@Transactional

View File

@ -32,6 +32,8 @@
<div class="row">
<div class="col-md-7 col-sm-12">
<input type="hidden" id="paperId" name="id" th:field="*{id}"/>
<input type="hidden" name="createDate" th:field="*{createDate}"/>
<input type="hidden" name="updateDate" th:field="*{updateDate}"/>
<div class="form-group">
<label for="title">Название:</label>
<input class="form-control" id="title" type="text"