From 689a7799e3803f5bc4f21a3584c39beaee4de2b2 Mon Sep 17 00:00:00 2001
From: Nightblade73
Date: Mon, 8 Apr 2019 22:04:30 +0400
Subject: [PATCH 1/2] #55 added method in controller
---
.../conference/controller/ConferenceController.java | 9 +++++++++
src/main/resources/templates/conferences/conference.html | 2 +-
.../conferences/fragments/confNavigationFragment.html | 2 +-
3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java
index 528975c..1de420b 100644
--- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java
+++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java
@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import ru.ulstu.conference.model.ConferenceDto;
import ru.ulstu.conference.model.ConferenceFilterDto;
import ru.ulstu.conference.service.ConferenceService;
+import ru.ulstu.deadline.model.Deadline;
import springfox.documentation.annotations.ApiIgnore;
import javax.validation.Valid;
@@ -61,6 +62,14 @@ public class ConferenceController {
}
+ @PostMapping(value = "/conference", params = "addDeadline")
+ public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) {
+ filterEmptyDeadlines(conferenceDto);
+ hasErrors(errors, CONFERENCE_PAGE);
+ conferenceDto.getDeadlines().add(new Deadline());
+ return CONFERENCE_PAGE;
+ }
+
private void filterEmptyDeadlines(ConferenceDto conferenceDto) {
conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream()
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html
index 3330bed..3917128 100644
--- a/src/main/resources/templates/conferences/conference.html
+++ b/src/main/resources/templates/conferences/conference.html
@@ -68,7 +68,7 @@
class="alert alert-danger">Incorrect title
-
diff --git a/src/main/resources/templates/conferences/fragments/confNavigationFragment.html b/src/main/resources/templates/conferences/fragments/confNavigationFragment.html
index 31cc00f..45a945e 100644
--- a/src/main/resources/templates/conferences/fragments/confNavigationFragment.html
+++ b/src/main/resources/templates/conferences/fragments/confNavigationFragment.html
@@ -21,7 +21,7 @@
From c308a5e5aff71b75e0cd6d93609c5da035dbeb9e Mon Sep 17 00:00:00 2001
From: Nightblade73
Date: Tue, 9 Apr 2019 14:47:14 +0400
Subject: [PATCH 2/2] #55 Navigation's method "hasErrors" don't work. it
returns String, not redirection.
---
.../ulstu/conference/controller/ConferenceController.java | 7 ++++---
src/main/resources/templates/conferences/conference.html | 6 +++++-
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java
index 1de420b..006a1de 100644
--- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java
+++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java
@@ -22,7 +22,6 @@ import static org.springframework.util.StringUtils.isEmpty;
import static ru.ulstu.core.controller.Navigation.CONFERENCES_PAGE;
import static ru.ulstu.core.controller.Navigation.CONFERENCE_PAGE;
import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
-import static ru.ulstu.core.controller.Navigation.hasErrors;
@Controller()
@@ -56,7 +55,8 @@ public class ConferenceController {
if (conferenceDto.getDeadlines().isEmpty()) {
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
}
- hasErrors(errors, CONFERENCE_PAGE);
+ if (errors.hasErrors())
+ return CONFERENCE_PAGE;
conferenceService.save(conferenceDto);
return String.format(REDIRECT_TO, CONFERENCES_PAGE);
@@ -65,7 +65,8 @@ public class ConferenceController {
@PostMapping(value = "/conference", params = "addDeadline")
public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) {
filterEmptyDeadlines(conferenceDto);
- hasErrors(errors, CONFERENCE_PAGE);
+ if (errors.hasErrors())
+ return CONFERENCE_PAGE;
conferenceDto.getDeadlines().add(new Deadline());
return CONFERENCE_PAGE;
}
diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html
index 3917128..cbc0019 100644
--- a/src/main/resources/templates/conferences/conference.html
+++ b/src/main/resources/templates/conferences/conference.html
@@ -30,6 +30,9 @@
+ Incorrect title
+
@@ -61,11 +64,12 @@
$('#deadlines${rowStat.index}\\.date').val('');
$('#addDeadline').click();|"/>
-
Incorrect title
+
+