|
|
@ -2,8 +2,10 @@ package ru.ulstu.project.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
|
|
|
|
|
import org.springframework.validation.Errors;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
|
|
|
|
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.project.model.Project;
|
|
|
|
import ru.ulstu.project.model.Project;
|
|
|
@ -11,7 +13,13 @@ import ru.ulstu.project.model.ProjectDto;
|
|
|
|
import ru.ulstu.project.service.ProjectService;
|
|
|
|
import ru.ulstu.project.service.ProjectService;
|
|
|
|
import springfox.documentation.annotations.ApiIgnore;
|
|
|
|
import springfox.documentation.annotations.ApiIgnore;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.springframework.util.StringUtils.isEmpty;
|
|
|
|
|
|
|
|
import static ru.ulstu.core.controller.Navigation.hasErrors;
|
|
|
|
|
|
|
|
|
|
|
|
@Controller()
|
|
|
|
@Controller()
|
|
|
|
@RequestMapping(value = "/projects")
|
|
|
|
@RequestMapping(value = "/projects")
|
|
|
@ -46,4 +54,21 @@ public class ProjectController {
|
|
|
|
public List<Project.ProjectStatus> getProjectStatuses() {
|
|
|
|
public List<Project.ProjectStatus> getProjectStatuses() {
|
|
|
|
return projectService.getProjectStatuses();
|
|
|
|
return projectService.getProjectStatuses();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/project", params = "save")
|
|
|
|
|
|
|
|
public String save(@Valid ProjectDto projectDto, Errors errors) throws IOException {
|
|
|
|
|
|
|
|
filterEmptyDeadlines(projectDto);
|
|
|
|
|
|
|
|
if (projectDto.getDeadlines().isEmpty()) {
|
|
|
|
|
|
|
|
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
hasErrors(errors, "/projects/project");
|
|
|
|
|
|
|
|
projectService.save(projectDto);
|
|
|
|
|
|
|
|
return String.format("redirect:%s", "/projects/projects");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void filterEmptyDeadlines(ProjectDto projectDto) {
|
|
|
|
|
|
|
|
projectDto.setDeadlines(projectDto.getDeadlines().stream()
|
|
|
|
|
|
|
|
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
|
|
|
|
|
|
|
.collect(Collectors.toList()));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|