#116 add removeDeadline method

This commit is contained in:
T-Midnight 2019-04-25 13:25:32 +04:00
parent 7c5a0826c5
commit 4fa0c14ae6
2 changed files with 17 additions and 0 deletions

View File

@ -97,6 +97,14 @@ public class GrantController {
return GRANT_PAGE;
}
@PostMapping(value = "/grant", params = "removeDeadline")
public String removeDeadline(GrantDto grantDto,
@RequestParam(value = "removeDeadline") Integer deadlineId) {
grantService.removeDeadline(grantDto, deadlineId);
return GRANT_PAGE;
}
@PostMapping(value = "/grant", params = "createProject")
public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException {
if (errors.hasErrors()) {

View File

@ -109,6 +109,7 @@ public class GrantService {
if (grantDto.getApplicationFileName() != null && grant.getApplication() != null) {
fileService.deleteFile(grant.getApplication());
}
grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
grantRepository.save(copyFromDto(grant, grantDto));
return grant.getId();
}
@ -184,4 +185,12 @@ public class GrantService {
grantDto.getPapers().clear();
}
}
public void removeDeadline(GrantDto grantDto, Integer deadlineId) {
if (grantDto.getDeadlines().get(deadlineId).getId() != null) {
grantDto.getRemovedDeadlineIds().add(grantDto.getDeadlines().get(deadlineId).getId());
}
grantDto.getDeadlines().remove((int) deadlineId);
}
}