|
|
@ -8,6 +8,8 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
|
|
import ru.ulstu.deadline.model.Deadline;
|
|
|
|
|
|
|
|
import ru.ulstu.grant.model.GrantDto;
|
|
|
|
import ru.ulstu.project.model.Project;
|
|
|
|
import ru.ulstu.project.model.Project;
|
|
|
|
import ru.ulstu.project.model.ProjectDto;
|
|
|
|
import ru.ulstu.project.model.ProjectDto;
|
|
|
|
import ru.ulstu.project.service.ProjectService;
|
|
|
|
import ru.ulstu.project.service.ProjectService;
|
|
|
@ -61,11 +63,23 @@ public class ProjectController {
|
|
|
|
if (projectDto.getDeadlines().isEmpty()) {
|
|
|
|
if (projectDto.getDeadlines().isEmpty()) {
|
|
|
|
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
|
|
|
|
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hasErrors(errors, "/projects/project");
|
|
|
|
if (errors.hasErrors()) {
|
|
|
|
|
|
|
|
return "/projects/project";
|
|
|
|
|
|
|
|
}
|
|
|
|
projectService.save(projectDto);
|
|
|
|
projectService.save(projectDto);
|
|
|
|
return String.format("redirect:%s", "/projects/projects");
|
|
|
|
return String.format("redirect:%s", "/projects/projects");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/project", params = "addDeadline")
|
|
|
|
|
|
|
|
public String addDeadline(@Valid ProjectDto projectDto, Errors errors) {
|
|
|
|
|
|
|
|
filterEmptyDeadlines(projectDto);
|
|
|
|
|
|
|
|
if (errors.hasErrors()) {
|
|
|
|
|
|
|
|
return "/projects/project";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
projectDto.getDeadlines().add(new Deadline());
|
|
|
|
|
|
|
|
return "/projects/project";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void filterEmptyDeadlines(ProjectDto projectDto) {
|
|
|
|
private void filterEmptyDeadlines(ProjectDto projectDto) {
|
|
|
|
projectDto.setDeadlines(projectDto.getDeadlines().stream()
|
|
|
|
projectDto.setDeadlines(projectDto.getDeadlines().stream()
|
|
|
|
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
|
|
|
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
|
|
|