From e350f8b3c161ca4f23445100b6b2a333e726d808 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 8 Apr 2019 07:40:26 +0400 Subject: [PATCH] #55 refactor controller navigation, fix conference edit url --- .../controller/ConferenceController.java | 11 +++++------ .../conference/model/ConferenceFilterDto.java | 4 ++++ .../controller/Navigation.java} | 9 +++++---- .../ulstu/grant/controller/GrantController.java | 8 ++++---- .../ru/ulstu/grant/controller/Navigation.java | 16 ---------------- .../conferences/fragments/confLineFragment.html | 2 +- 6 files changed, 19 insertions(+), 31 deletions(-) rename src/main/java/ru/ulstu/{conference/controller/NavigationController.java => core/controller/Navigation.java} (69%) delete mode 100644 src/main/java/ru/ulstu/grant/controller/Navigation.java diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index c3b4917..528975c 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -18,10 +18,10 @@ import java.io.IOException; import java.util.stream.Collectors; import static org.springframework.util.StringUtils.isEmpty; -import static ru.ulstu.conference.controller.NavigationController.CONFERENCES_PAGE; -import static ru.ulstu.conference.controller.NavigationController.CONFERENCE_PAGE; -import static ru.ulstu.conference.controller.NavigationController.REDIRECT_TO; -import static ru.ulstu.grant.controller.Navigation.hasErrors; +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() @@ -37,8 +37,7 @@ public class ConferenceController { @GetMapping("/conferences") public void getConferences(ModelMap modelMap) { - modelMap.put("filteredConferences", new ConferenceFilterDto(conferenceService.findAllDto(), - null, null)); + modelMap.put("filteredConferences", new ConferenceFilterDto(conferenceService.findAllDto())); } @GetMapping("/conference") diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java index 5b85839..37878b2 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java @@ -17,6 +17,10 @@ public class ConferenceFilterDto { this.year = year; } + public ConferenceFilterDto(List conferenceDtos) { + this(conferenceDtos, null, null); + } + public List getConferences() { return conferences; } diff --git a/src/main/java/ru/ulstu/conference/controller/NavigationController.java b/src/main/java/ru/ulstu/core/controller/Navigation.java similarity index 69% rename from src/main/java/ru/ulstu/conference/controller/NavigationController.java rename to src/main/java/ru/ulstu/core/controller/Navigation.java index 84f88ad..caea429 100644 --- a/src/main/java/ru/ulstu/conference/controller/NavigationController.java +++ b/src/main/java/ru/ulstu/core/controller/Navigation.java @@ -1,10 +1,12 @@ -package ru.ulstu.conference.controller; +package ru.ulstu.core.controller; import org.springframework.validation.Errors; -public class NavigationController { - +public class Navigation { public static final String REDIRECT_TO = "redirect:%s"; + public static final String GRANTS_PAGE = "/grants/grants"; + public static final String GRANT_PAGE = "/grants/grant"; + public static final String CONFERENCES_PAGE = "/conferences/conferences"; public static final String CONFERENCE_PAGE = "/conferences/conference"; @@ -14,5 +16,4 @@ public class NavigationController { } return null; } - } diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index 65b11dc..a7dc948 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -21,10 +21,10 @@ import java.util.List; import java.util.stream.Collectors; 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; +import static ru.ulstu.core.controller.Navigation.GRANTS_PAGE; +import static ru.ulstu.core.controller.Navigation.GRANT_PAGE; +import static ru.ulstu.core.controller.Navigation.REDIRECT_TO; +import static ru.ulstu.core.controller.Navigation.hasErrors; @Controller() diff --git a/src/main/java/ru/ulstu/grant/controller/Navigation.java b/src/main/java/ru/ulstu/grant/controller/Navigation.java deleted file mode 100644 index bf1626f..0000000 --- a/src/main/java/ru/ulstu/grant/controller/Navigation.java +++ /dev/null @@ -1,16 +0,0 @@ -package ru.ulstu.grant.controller; - -import org.springframework.validation.Errors; - -public class Navigation { - public static final String REDIRECT_TO = "redirect:%s"; - public static final String GRANTS_PAGE = "/grants/grants"; - public static final String GRANT_PAGE = "/grants/grant"; - - public static String hasErrors(Errors errors, String page) { - if (errors.hasErrors()) { - return page; - } - return null; - } -} diff --git a/src/main/resources/templates/conferences/fragments/confLineFragment.html b/src/main/resources/templates/conferences/fragments/confLineFragment.html index c97dfbd..317da03 100644 --- a/src/main/resources/templates/conferences/fragments/confLineFragment.html +++ b/src/main/resources/templates/conferences/fragments/confLineFragment.html @@ -6,7 +6,7 @@