fix submit form
This commit is contained in:
parent
d5121c895e
commit
3e8b74f362
@ -48,6 +48,10 @@ public class PaperController {
|
||||
|
||||
@PostMapping(value = "/paper", params = "save")
|
||||
public String save(@Valid PaperDto paperDto, Errors errors) throws IOException {
|
||||
filterEmptyDeadlines(paperDto);
|
||||
if (paperDto.getDeadlines().isEmpty()) {
|
||||
errors.rejectValue("deadlines", "errorCode","Не может быть пустым");
|
||||
}
|
||||
if (errors.hasErrors()) {
|
||||
return "/papers/paper";
|
||||
}
|
||||
|
@ -158,6 +158,7 @@ public class Paper extends BaseEntity implements UserContainer {
|
||||
public Optional<Deadline> getNextDeadline() {
|
||||
return deadlines
|
||||
.stream()
|
||||
.filter(deadline -> deadline.getDate() != null)
|
||||
.sorted(Comparator.comparing(Deadline::getDate))
|
||||
.filter(d -> d.getDate().after(new Date()))
|
||||
.findFirst();
|
||||
|
@ -6,6 +6,7 @@ import org.hibernate.validator.constraints.NotEmpty;
|
||||
import ru.ulstu.deadline.model.DeadlineDto;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -21,7 +22,7 @@ public class PaperDto {
|
||||
private Date createDate;
|
||||
private Date updateDate;
|
||||
@NotEmpty
|
||||
private List<DeadlineDto> deadlines;
|
||||
private List<DeadlineDto> deadlines = new ArrayList<>();
|
||||
private String comment;
|
||||
private Boolean locked;
|
||||
private String tmpFileName;
|
||||
@ -31,7 +32,7 @@ public class PaperDto {
|
||||
private Set<Integer> authors;
|
||||
|
||||
public PaperDto() {
|
||||
|
||||
deadlines.add(new DeadlineDto());
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
|
Loading…
Reference in New Issue
Block a user