24
24
import javax .validation .Valid ;
25
25
26
26
import org .springframework .beans .propertyeditors .StringTrimmerEditor ;
27
+ import org .springframework .http .HttpStatus ;
27
28
import org .springframework .stereotype .Controller ;
28
29
import org .springframework .ui .Model ;
29
30
import org .springframework .validation .BindingResult ;
32
33
import org .springframework .web .bind .annotation .PathVariable ;
33
34
import org .springframework .web .bind .annotation .RequestMapping ;
34
35
import org .springframework .web .bind .annotation .RequestMethod ;
36
+ import org .springframework .web .servlet .View ;
35
37
import org .springframework .web .servlet .mvc .support .RedirectAttributes ;
38
+ import org .springframework .web .servlet .view .RedirectView ;
36
39
import org .springframework .web .util .UriComponentsBuilder ;
37
40
38
41
import lombok .RequiredArgsConstructor ;
@@ -80,7 +83,7 @@ public String processInput(
80
83
UrlEntityDto countryUrl = countryService .add (form , currentUserId );
81
84
82
85
String dstUrl = UriComponentsBuilder .fromUriString (Url .INFO_COUNTRY_PAGE )
83
- .buildAndExpand (countryUrl .getId (), countryUrl . getSlug ())
86
+ .buildAndExpand (countryUrl .getSlug ())
84
87
.toString ();
85
88
86
89
redirectAttributes .addFlashAttribute ("justAddedCountry" , true );
@@ -89,8 +92,8 @@ public String processInput(
89
92
}
90
93
91
94
@ RequestMapping (Url .INFO_COUNTRY_PAGE )
92
- public String showInfo (
93
- @ Country @ PathVariable ("id " ) LinkEntityDto country ,
95
+ public String showInfoBySlug (
96
+ @ Country @ PathVariable ("slug " ) LinkEntityDto country ,
94
97
Model model ,
95
98
Locale userLocale ,
96
99
HttpServletResponse response )
@@ -112,6 +115,27 @@ public String showInfo(
112
115
return "country/info" ;
113
116
}
114
117
118
+ /**
119
+ * @author Aleksander Parkhomenko
120
+ */
121
+ @ RequestMapping (Url .INFO_COUNTRY_BY_ID_PAGE )
122
+ public View showInfoById (
123
+ @ Country @ PathVariable ("slug" ) LinkEntityDto country ,
124
+ HttpServletResponse response )
125
+ throws IOException {
126
+
127
+ if (country == null ) {
128
+ response .sendError (HttpServletResponse .SC_NOT_FOUND );
129
+ return null ;
130
+ }
131
+
132
+ RedirectView view = new RedirectView ();
133
+ view .setStatusCode (HttpStatus .MOVED_PERMANENTLY );
134
+ view .setUrl (Url .INFO_COUNTRY_PAGE );
135
+
136
+ return view ;
137
+ }
138
+
115
139
@ RequestMapping (Url .LIST_COUNTRIES_PAGE )
116
140
public void list (Model model , Locale userLocale ) {
117
141
String lang = LocaleUtils .getLanguageOrNull (userLocale );
0 commit comments