Skip to content

Commit 648d38c

Browse files
committed
refactor: move a method from CountryController to SeriesController to reduce a coupling.
Fix #1052
1 parent 8040958 commit 648d38c

File tree

5 files changed

+32
-38
lines changed

5 files changed

+32
-38
lines changed

src/main/java/ru/mystamps/web/feature/country/CountryConfig.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.springframework.context.annotation.Bean;
2323
import org.springframework.context.annotation.Configuration;
2424
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
25-
import ru.mystamps.web.feature.series.SeriesService;
2625

2726
/**
2827
* Spring configuration that is required for using countries in an application.
@@ -37,11 +36,10 @@ public class CountryConfig {
3736
public static class Controllers {
3837

3938
private final CountryService countryService;
40-
private final SeriesService seriesService;
4139

4240
@Bean
4341
public CountryController countryController() {
44-
return new CountryController(countryService, seriesService);
42+
return new CountryController(countryService);
4543
}
4644

4745
@Bean

src/main/java/ru/mystamps/web/feature/country/CountryController.java

+3-33
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
import org.springframework.web.servlet.view.RedirectView;
3333
import ru.mystamps.web.common.LinkEntityDto;
3434
import ru.mystamps.web.common.LocaleUtils;
35-
import ru.mystamps.web.feature.series.SeriesInfoDto;
36-
import ru.mystamps.web.feature.series.SeriesService;
35+
import ru.mystamps.web.feature.series.SeriesUrl;
3736
import ru.mystamps.web.support.spring.mvc.ReplaceRepeatingSpacesEditor;
3837
import ru.mystamps.web.support.spring.security.CurrentUser;
3938

@@ -50,7 +49,6 @@
5049
public class CountryController {
5150

5251
private final CountryService countryService;
53-
private final SeriesService seriesService;
5452

5553
@InitBinder("addCountryForm")
5654
protected void initBinder(WebDataBinder binder) {
@@ -81,35 +79,7 @@ public String processInput(
8179

8280
redirectAttributes.addFlashAttribute("justAddedCountry", true);
8381

84-
return redirectTo(CountryUrl.INFO_COUNTRY_PAGE, slug);
85-
}
86-
87-
// CheckStyle: ignore LineLength for next 1 line
88-
// @todo #927 CountryController: remove dependency on SeriesService by moving showInfoBySlug() method
89-
@GetMapping(CountryUrl.INFO_COUNTRY_PAGE)
90-
public String showInfoBySlug(
91-
@Country @PathVariable("slug") LinkEntityDto country,
92-
Model model,
93-
Locale userLocale,
94-
HttpServletResponse response)
95-
throws IOException {
96-
97-
if (country == null) {
98-
response.sendError(HttpServletResponse.SC_NOT_FOUND);
99-
return null;
100-
}
101-
102-
String slug = country.getSlug();
103-
String name = country.getName();
104-
105-
String lang = LocaleUtils.getLanguageOrNull(userLocale);
106-
List<SeriesInfoDto> series = seriesService.findByCountrySlug(slug, lang);
107-
108-
model.addAttribute("countrySlug", slug);
109-
model.addAttribute("countryName", name);
110-
model.addAttribute("seriesOfCountry", series);
111-
112-
return "country/info";
82+
return redirectTo(SeriesUrl.INFO_COUNTRY_PAGE, slug);
11383
}
11484

11585
/**
@@ -128,7 +98,7 @@ public View showInfoById(
12898

12999
RedirectView view = new RedirectView();
130100
view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
131-
view.setUrl(CountryUrl.INFO_COUNTRY_PAGE);
101+
view.setUrl(SeriesUrl.INFO_COUNTRY_PAGE);
132102

133103
return view;
134104
}

src/main/java/ru/mystamps/web/feature/country/CountryUrl.java

-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public final class CountryUrl {
3232
public static final String SUGGEST_SERIES_COUNTRY = "/suggest/series_country";
3333
public static final String ADD_COUNTRY_PAGE = "/country/add";
3434
static final String GET_COUNTRIES_PAGE = "/countries";
35-
static final String INFO_COUNTRY_PAGE = "/country/{slug}";
3635

3736
// For backward compatibility
3837
static final String LIST_COUNTRIES_PAGE = "/country/list";
@@ -44,7 +43,6 @@ private CountryUrl() {
4443
public static void exposeUrlsToView(Map<String, String> urls) {
4544
urls.put("ADD_COUNTRY_PAGE", ADD_COUNTRY_PAGE);
4645
urls.put("GET_COUNTRIES_PAGE", GET_COUNTRIES_PAGE);
47-
urls.put("INFO_COUNTRY_PAGE", INFO_COUNTRY_PAGE);
4846
urls.put("SUGGEST_SERIES_COUNTRY", SUGGEST_SERIES_COUNTRY);
4947
}
5048

src/main/java/ru/mystamps/web/feature/series/SeriesController.java

+26
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,32 @@ public String showInfo(
255255
return "series/info";
256256
}
257257

258+
@GetMapping(SeriesUrl.INFO_COUNTRY_PAGE)
259+
public String showInfoByCountrySlug(
260+
@Country @PathVariable("slug") LinkEntityDto country,
261+
Model model,
262+
Locale userLocale,
263+
HttpServletResponse response)
264+
throws IOException {
265+
266+
if (country == null) {
267+
response.sendError(HttpServletResponse.SC_NOT_FOUND);
268+
return null;
269+
}
270+
271+
String slug = country.getSlug();
272+
String name = country.getName();
273+
274+
String lang = LocaleUtils.getLanguageOrNull(userLocale);
275+
List<SeriesInfoDto> series = seriesService.findByCountrySlug(slug, lang);
276+
277+
model.addAttribute("countrySlug", slug);
278+
model.addAttribute("countryName", name);
279+
model.addAttribute("seriesOfCountry", series);
280+
281+
return "country/info";
282+
}
283+
258284
@SuppressWarnings("checkstyle:parameternumber")
259285
@PostMapping(path = SeriesUrl.ADD_IMAGE_SERIES_PAGE, params = "imageUrl")
260286
public String processImageWithImageUrl(

src/main/java/ru/mystamps/web/feature/series/SeriesUrl.java

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public final class SeriesUrl {
3232
public static final String ADD_SERIES_PAGE = "/series/add";
3333
public static final String ADD_SERIES_ASK_PAGE = "/series/{id}/ask";
3434
public static final String INFO_SERIES_PAGE = "/series/{id}";
35+
public static final String INFO_COUNTRY_PAGE = "/country/{slug}";
3536
public static final String ADD_IMAGE_SERIES_PAGE = "/series/{id}/image";
3637
public static final String SERIES_INFO_PAGE_REGEXP = "/series/(\\d+|\\d+/(ask|image))";
3738
static final String SEARCH_SERIES_BY_CATALOG = "/series/search/by_catalog";
@@ -47,6 +48,7 @@ public static void exposeUrlsToView(Map<String, String> urls) {
4748
urls.put("ADD_IMAGE_SERIES_PAGE", ADD_IMAGE_SERIES_PAGE);
4849
urls.put("ADD_SERIES_ASK_PAGE", ADD_SERIES_ASK_PAGE);
4950
urls.put("ADD_SERIES_PAGE", ADD_SERIES_PAGE);
51+
urls.put("INFO_COUNTRY_PAGE", INFO_COUNTRY_PAGE);
5052
urls.put("INFO_SERIES_PAGE", INFO_SERIES_PAGE);
5153
urls.put("SEARCH_SERIES_BY_CATALOG", SEARCH_SERIES_BY_CATALOG);
5254
}

0 commit comments

Comments
 (0)