From 4fa0c14ae62904f2e4509c5784c44752d6f8fb6a Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 25 Apr 2019 13:25:32 +0400 Subject: [PATCH] #116 add removeDeadline method --- .../java/ru/ulstu/grant/controller/GrantController.java | 8 ++++++++ src/main/java/ru/ulstu/grant/service/GrantService.java | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index 92ce826..85a0cd9 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -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()) { diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 1f0b6ce..cabed80 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -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); + } + }