From 6d6ea3136d1a784b1a7b33e86c9cf32760ded40a Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Tue, 23 Apr 2019 13:37:56 +0400 Subject: [PATCH] #64 dont show error message --- .../controller/ConferenceController.java | 10 +++++++++- .../conference/model/ConferenceFilterDto.java | 8 ++++---- .../ru/ulstu/paper/controller/PaperController.java | 12 ++++++++++-- .../templates/conferences/conferences.html | 14 +++++++++++--- src/main/resources/templates/papers/papers.html | 9 +++++++-- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index a143e3b..8560f43 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -68,7 +68,15 @@ public class ConferenceController { } @PostMapping(value = "/conferences", params = "deleteConference") - public String delete(@RequestParam("deleteConference") Integer conferenceId) throws IOException { + public String delete(@Valid ConferenceFilterDto conferenceFilterDto, + @RequestParam("deleteConference") Integer conferenceId, + Errors errors, + ModelMap modelMap) throws IOException { + if (true) { + errors.reject("relationExist", "Статья прикреплена к конференции"); + filterConferences(conferenceFilterDto, modelMap); + return CONFERENCES_PAGE; + } conferenceService.delete(conferenceId); return String.format(REDIRECT_TO, CONFERENCES_PAGE); } diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java index 8503b40..0649901 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java @@ -11,14 +11,14 @@ public class ConferenceFilterDto { public ConferenceFilterDto() { } - public ConferenceFilterDto(List conferenceDtos, Integer filterUserId, Integer year) { - this.conferences = conferenceDtos; + public ConferenceFilterDto(List conferences, Integer filterUserId, Integer year) { + this.conferences = conferences; this.filterUserId = filterUserId; this.year = year; } - public ConferenceFilterDto(List conferenceDtos) { - this(conferenceDtos, null, null); + public ConferenceFilterDto(List conferences) { + this(conferences, null, null); } public List getConferences() { diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index e11e4d9..4b13275 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -1,5 +1,6 @@ package ru.ulstu.paper.controller; +import org.springframework.dao.DataIntegrityViolationException; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -95,8 +96,15 @@ public class PaperController { } @GetMapping("/delete/{paper-id}") - public String delete(@PathVariable("paper-id") Integer paperId) throws IOException { - paperService.delete(paperId); + public String delete(@Valid PaperFilterDto paperFilterDto, + @PathVariable("paper-id") Integer paperId, + Errors errors) throws IOException { + try { + paperService.delete(paperId); + } catch (DataIntegrityViolationException e) { + errors.reject("relationExist", "Статья прикреплена к конференции"); + return "/papers/papers"; + } return "redirect:/papers/papers"; } diff --git a/src/main/resources/templates/conferences/conferences.html b/src/main/resources/templates/conferences/conferences.html index f471245..5f3f127 100644 --- a/src/main/resources/templates/conferences/conferences.html +++ b/src/main/resources/templates/conferences/conferences.html @@ -8,7 +8,9 @@
-
+ +
@@ -18,10 +20,16 @@

+ + +
+

+
+ +
- - +
diff --git a/src/main/resources/templates/papers/papers.html b/src/main/resources/templates/papers/papers.html index 7a033fe..5efd860 100644 --- a/src/main/resources/templates/papers/papers.html +++ b/src/main/resources/templates/papers/papers.html @@ -7,7 +7,8 @@
- +
@@ -17,7 +18,11 @@
+
+
+

+
@@ -43,7 +48,7 @@
-
+