|
|
@ -20,6 +20,10 @@ import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.springframework.util.StringUtils.isEmpty;
|
|
|
|
import static org.springframework.util.StringUtils.isEmpty;
|
|
|
|
|
|
|
|
import static ru.ulstu.grant.controller.Navigation.GRANTS_PAGE;
|
|
|
|
|
|
|
|
import static ru.ulstu.grant.controller.Navigation.GRANT_PAGE;
|
|
|
|
|
|
|
|
import static ru.ulstu.grant.controller.Navigation.REDIRECT_TO;
|
|
|
|
|
|
|
|
import static ru.ulstu.grant.controller.Navigation.hasErrors;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller()
|
|
|
|
@Controller()
|
|
|
@ -56,36 +60,30 @@ public class GrantController {
|
|
|
|
if (grantDto.getDeadlines().isEmpty()) {
|
|
|
|
if (grantDto.getDeadlines().isEmpty()) {
|
|
|
|
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
|
|
|
|
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (errors.hasErrors()) {
|
|
|
|
hasErrors(errors, GRANT_PAGE);
|
|
|
|
return "/grants/grant";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
grantService.save(grantDto);
|
|
|
|
grantService.save(grantDto);
|
|
|
|
return "redirect:/grants/grants";
|
|
|
|
return String.format(REDIRECT_TO, GRANTS_PAGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/grant", params = "addDeadline")
|
|
|
|
@PostMapping(value = "/grant", params = "addDeadline")
|
|
|
|
public String addDeadline(@Valid GrantDto grantDto, Errors errors) {
|
|
|
|
public String addDeadline(@Valid GrantDto grantDto, Errors errors) {
|
|
|
|
filterEmptyDeadlines(grantDto);
|
|
|
|
filterEmptyDeadlines(grantDto);
|
|
|
|
if (errors.hasErrors()) {
|
|
|
|
hasErrors(errors, GRANT_PAGE);
|
|
|
|
return "/grants/grant";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
grantDto.getDeadlines().add(new DeadlineDto());
|
|
|
|
grantDto.getDeadlines().add(new DeadlineDto());
|
|
|
|
return "/grants/grant";
|
|
|
|
return GRANT_PAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/grant", params = "createProject")
|
|
|
|
@PostMapping(value = "/grant", params = "createProject")
|
|
|
|
public String createProject(@Valid GrantDto grantDto, Errors errors) {
|
|
|
|
public String createProject(@Valid GrantDto grantDto, Errors errors) {
|
|
|
|
if (errors.hasErrors()) {
|
|
|
|
hasErrors(errors, GRANT_PAGE);
|
|
|
|
return "/grants/grant";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
grantService.createProject(grantDto);
|
|
|
|
grantService.createProject(grantDto);
|
|
|
|
return "/grants/grant";
|
|
|
|
return GRANT_PAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/delete/{grant-id}")
|
|
|
|
@GetMapping("/delete/{grant-id}")
|
|
|
|
public String delete(@PathVariable("grant-id") Integer grantId) throws IOException {
|
|
|
|
public String delete(@PathVariable("grant-id") Integer grantId) throws IOException {
|
|
|
|
grantService.delete(grantId);
|
|
|
|
grantService.delete(grantId);
|
|
|
|
return "redirect:/grants/grants";
|
|
|
|
return String.format(REDIRECT_TO, GRANTS_PAGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ModelAttribute("allStatuses")
|
|
|
|
@ModelAttribute("allStatuses")
|
|
|
|