fix submit form

This commit is contained in:
Anton Romanov 2018-12-17 17:56:48 +04:00
parent d5121c895e
commit 3e8b74f362
3 changed files with 8 additions and 2 deletions

View File

@ -48,6 +48,10 @@ public class PaperController {
@PostMapping(value = "/paper", params = "save") @PostMapping(value = "/paper", params = "save")
public String save(@Valid PaperDto paperDto, Errors errors) throws IOException { public String save(@Valid PaperDto paperDto, Errors errors) throws IOException {
filterEmptyDeadlines(paperDto);
if (paperDto.getDeadlines().isEmpty()) {
errors.rejectValue("deadlines", "errorCode","Не может быть пустым");
}
if (errors.hasErrors()) { if (errors.hasErrors()) {
return "/papers/paper"; return "/papers/paper";
} }

View File

@ -158,6 +158,7 @@ public class Paper extends BaseEntity implements UserContainer {
public Optional<Deadline> getNextDeadline() { public Optional<Deadline> getNextDeadline() {
return deadlines return deadlines
.stream() .stream()
.filter(deadline -> deadline.getDate() != null)
.sorted(Comparator.comparing(Deadline::getDate)) .sorted(Comparator.comparing(Deadline::getDate))
.filter(d -> d.getDate().after(new Date())) .filter(d -> d.getDate().after(new Date()))
.findFirst(); .findFirst();

View File

@ -6,6 +6,7 @@ import org.hibernate.validator.constraints.NotEmpty;
import ru.ulstu.deadline.model.DeadlineDto; import ru.ulstu.deadline.model.DeadlineDto;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -21,7 +22,7 @@ public class PaperDto {
private Date createDate; private Date createDate;
private Date updateDate; private Date updateDate;
@NotEmpty @NotEmpty
private List<DeadlineDto> deadlines; private List<DeadlineDto> deadlines = new ArrayList<>();
private String comment; private String comment;
private Boolean locked; private Boolean locked;
private String tmpFileName; private String tmpFileName;
@ -31,7 +32,7 @@ public class PaperDto {
private Set<Integer> authors; private Set<Integer> authors;
public PaperDto() { public PaperDto() {
deadlines.add(new DeadlineDto());
} }
@JsonCreator @JsonCreator