Skip to content

Commit e579d53

Browse files
committed
Change URL of the create series page to use request parameter insted of URL variable.
/series/add/category/{slug} -> /series/add?category={slug} /series/add/country/{slug} -> /series/add?country={slug} Now it's also possible to specify both category and country in URL: /series/add?category={slug}&country={slug} Addressed to #514 No functional changes.
1 parent 6351bb8 commit e579d53

File tree

5 files changed

+35
-29
lines changed

5 files changed

+35
-29
lines changed

src/main/java/ru/mystamps/web/Url.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ public final class Url {
4747
public static final String LOGOUT_PAGE = "/account/logout";
4848
public static final String ACTIVATE_ACCOUNT_PAGE = "/account/activate";
4949

50-
// CheckStyle: ignore LineLength for next 3 lines
5150
public static final String ADD_SERIES_PAGE = "/series/add";
52-
public static final String ADD_SERIES_WITH_CATEGORY_PAGE = "/series/add/category/{slug}";
53-
public static final String ADD_SERIES_WITH_COUNTRY_PAGE = "/series/add/country/{slug}";
5451
public static final String ADD_SERIES_ASK_PAGE = "/series/{id}/ask";
5552
public static final String INFO_SERIES_PAGE = "/series/{id}";
5653
public static final String ADD_IMAGE_SERIES_PAGE = "/series/{id}/image";
@@ -78,6 +75,8 @@ public final class Url {
7875
public static final String INFO_CATEGORY_BY_ID_PAGE = "/category/{id}/{slug}";
7976
public static final String INFO_COUNTRY_BY_ID_PAGE = "/country/{id}/{slug}";
8077
public static final String INFO_COLLECTION_BY_ID_PAGE = "/collection/{id}/{slug}";
78+
public static final String ADD_SERIES_WITH_CATEGORY_PAGE = "/series/add/category/{slug}";
79+
public static final String ADD_SERIES_WITH_COUNTRY_PAGE = "/series/add/country/{slug}";
8180

8281
// MUST be updated when any of our resources were modified
8382
public static final String RESOURCES_VERSION = "v0.3.0";
@@ -124,8 +123,6 @@ public static Map<String, String> asMap(boolean serveContentFromSingleHost) {
124123
map.put("ACTIVATE_ACCOUNT_PAGE", ACTIVATE_ACCOUNT_PAGE);
125124
map.put("REGISTRATION_PAGE", REGISTRATION_PAGE);
126125
map.put("ADD_SERIES_PAGE", ADD_SERIES_PAGE);
127-
map.put("ADD_SERIES_WITH_CATEGORY_PAGE", ADD_SERIES_WITH_CATEGORY_PAGE);
128-
map.put("ADD_SERIES_WITH_COUNTRY_PAGE", ADD_SERIES_WITH_COUNTRY_PAGE);
129126
map.put("ADD_SERIES_ASK_PAGE", ADD_SERIES_ASK_PAGE);
130127
map.put("INFO_SERIES_PAGE", INFO_SERIES_PAGE);
131128
map.put("ADD_IMAGE_SERIES_PAGE", ADD_IMAGE_SERIES_PAGE);

src/main/java/ru/mystamps/web/controller/SeriesController.java

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.commons.lang3.StringUtils;
3737

3838
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
39+
import org.springframework.http.HttpStatus;
3940
import org.springframework.stereotype.Controller;
4041
import org.springframework.ui.Model;
4142
import org.springframework.validation.BindingResult;
@@ -47,7 +48,9 @@
4748
import org.springframework.web.bind.annotation.PathVariable;
4849
import org.springframework.web.bind.annotation.PostMapping;
4950
import org.springframework.web.bind.annotation.RequestParam;
51+
import org.springframework.web.servlet.View;
5052
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
53+
import org.springframework.web.servlet.view.RedirectView;
5154

5255
import org.springframework.security.core.annotation.AuthenticationPrincipal;
5356

@@ -132,40 +135,50 @@ public List<LinkEntityDto> getCountries(Locale userLocale) {
132135
}
133136

134137
@GetMapping(Url.ADD_SERIES_PAGE)
135-
public AddSeriesForm showForm() {
138+
public AddSeriesForm showForm(
139+
@Category @RequestParam(name = "category", required = false) LinkEntityDto category,
140+
@Country @RequestParam(name = "country", required = false) LinkEntityDto country) {
136141

137142
AddSeriesForm addSeriesForm = new AddSeriesForm();
138143
addSeriesForm.setPerforated(true);
139144

145+
if (category != null) {
146+
addSeriesForm.setCategory(category);
147+
}
148+
149+
if (country != null) {
150+
addSeriesForm.setCountry(country);
151+
}
152+
140153
return addSeriesForm;
141154
}
142155

143156
@GetMapping(Url.ADD_SERIES_WITH_CATEGORY_PAGE)
144-
public String showFormWithCategory(
145-
@Category @PathVariable("slug") LinkEntityDto category,
146-
Model model) {
157+
public View showFormWithCategory(
158+
@PathVariable("slug") String category,
159+
RedirectAttributes redirectAttributes) {
147160

148-
AddSeriesForm form = new AddSeriesForm();
149-
form.setPerforated(true);
150-
form.setCategory(category);
161+
redirectAttributes.addAttribute("category", category);
151162

152-
model.addAttribute("addSeriesForm", form);
163+
RedirectView view = new RedirectView();
164+
view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
165+
view.setUrl(Url.ADD_SERIES_PAGE);
153166

154-
return "series/add";
167+
return view;
155168
}
156169

157170
@GetMapping(Url.ADD_SERIES_WITH_COUNTRY_PAGE)
158-
public String showFormWithCountry(
159-
@Country @PathVariable("slug") LinkEntityDto country,
160-
Model model) {
171+
public View showFormWithCountry(
172+
@PathVariable("slug") String country,
173+
RedirectAttributes redirectAttributes) {
161174

162-
AddSeriesForm form = new AddSeriesForm();
163-
form.setPerforated(true);
164-
form.setCountry(country);
175+
redirectAttributes.addAttribute("country", country);
165176

166-
model.addAttribute("addSeriesForm", form);
177+
RedirectView view = new RedirectView();
178+
view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
179+
view.setUrl(Url.ADD_SERIES_PAGE);
167180

168-
return "series/add";
181+
return view;
169182
}
170183

171184
@PostMapping(Url.ADD_SERIES_PAGE)

src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ protected void configure(HttpSecurity http) throws Exception {
6666
.hasAuthority(StringAuthority.CREATE_CATEGORY)
6767
.mvcMatchers(Url.ADD_COUNTRY_PAGE)
6868
.hasAuthority(StringAuthority.CREATE_COUNTRY)
69-
.mvcMatchers(
70-
Url.ADD_SERIES_PAGE,
71-
Url.ADD_SERIES_WITH_CATEGORY_PAGE.replace("{slug}", "**"),
72-
Url.ADD_SERIES_WITH_COUNTRY_PAGE.replace("{slug}", "**")
73-
)
69+
.mvcMatchers(Url.ADD_SERIES_PAGE)
7470
.hasAuthority(StringAuthority.CREATE_SERIES)
7571
.mvcMatchers(Url.SITE_EVENTS_PAGE)
7672
.hasAuthority(StringAuthority.VIEW_SITE_EVENTS)

src/main/webapp/WEB-INF/views/category/info.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ <h3 th:text="${categoryName}">
9595

9696
<!--/*/
9797
<div class="row" th:if="${justAddedCategory}">
98-
<div class="alert alert-success text-center col-sm-4 col-sm-offset-4" th:utext="#{t_category_just_added(@{${ADD_SERIES_WITH_CATEGORY_PAGE}(slug=${categorySlug})})}">
98+
<div class="alert alert-success text-center col-sm-4 col-sm-offset-4" th:utext="#{t_category_just_added(@{${ADD_SERIES_PAGE}(category=${categorySlug})})}">
9999
Category has been added.<br />
100100
Now you could <a href="../series/add.html" class="alert-link">proceed with creating series</a>.
101101
</div>

src/main/webapp/WEB-INF/views/country/info.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ <h3 th:text="${#strings.capitalize(header)}">
9595

9696
<!--/*/
9797
<div class="row" th:if="${justAddedCountry}">
98-
<div class="alert alert-success text-center col-sm-4 col-sm-offset-4" th:utext="#{t_country_just_added(@{${ADD_SERIES_WITH_COUNTRY_PAGE}(slug=${countrySlug})})}">
98+
<div class="alert alert-success text-center col-sm-4 col-sm-offset-4" th:utext="#{t_country_just_added(@{${ADD_SERIES_PAGE}(country=${countrySlug})})}">
9999
Country has been added.<br />
100100
Now you could <a href="../series/add.html" class="alert-link">proceed with creating series</a>.
101101
</div>

0 commit comments

Comments
 (0)