Skip to content

Commit 755d564

Browse files
committed
refactor(ImageUrl): move image-related values to the corresponding class.
Addressed to #927 No functional changes.
1 parent 9847e80 commit 755d564

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import ru.mystamps.web.feature.category.CategoryUrl;
2222
import ru.mystamps.web.feature.collection.CollectionUrl;
2323
import ru.mystamps.web.feature.country.CountryUrl;
24+
import ru.mystamps.web.feature.image.ImageUrl;
2425
import ru.mystamps.web.feature.participant.ParticipantUrl;
2526

2627
import java.util.HashMap;
@@ -63,9 +64,6 @@ public final class Url {
6364
public static final String SUGGEST_SERIES_CATEGORY = "/suggest/series_category";
6465
public static final String SUGGEST_SERIES_COUNTRY = "/suggest/series_country";
6566

66-
public static final String GET_IMAGE_PAGE = "/image/{id}";
67-
public static final String GET_IMAGE_PREVIEW_PAGE = "/image/preview/{id}";
68-
6967
public static final String FORBIDDEN_PAGE = "/error/403";
7068
public static final String NOT_FOUND_PAGE = "/error/404";
7169
public static final String INTERNAL_ERROR_PAGE = "/error/500";
@@ -159,8 +157,8 @@ public static Map<String, String> asMap(boolean production) {
159157
map.put("COLLECTION_INFO_JS", COLLECTION_INFO_JS);
160158
map.put("DATE_UTILS_JS", DATE_UTILS_JS);
161159
map.put("FAVICON_ICO", FAVICON_ICO);
162-
map.put("GET_IMAGE_PAGE", GET_IMAGE_PAGE);
163-
map.put("GET_IMAGE_PREVIEW_PAGE", GET_IMAGE_PREVIEW_PAGE);
160+
map.put("GET_IMAGE_PAGE", ImageUrl.GET_IMAGE_PAGE);
161+
map.put("GET_IMAGE_PREVIEW_PAGE", ImageUrl.GET_IMAGE_PREVIEW_PAGE);
164162
map.put("JQUERY_JS", JQUERY_JS);
165163
map.put("MAIN_CSS", MAIN_CSS);
166164
map.put("PARTICIPANT_ADD_JS", PARTICIPANT_ADD_JS);
@@ -175,8 +173,9 @@ public static Map<String, String> asMap(boolean production) {
175173
map.put("COLLECTION_INFO_JS", STATIC_RESOURCES_URL + COLLECTION_INFO_JS);
176174
map.put("DATE_UTILS_JS", STATIC_RESOURCES_URL + DATE_UTILS_JS);
177175
map.put("FAVICON_ICO", STATIC_RESOURCES_URL + FAVICON_ICO);
178-
map.put("GET_IMAGE_PAGE", STATIC_RESOURCES_URL + GET_IMAGE_PAGE);
179-
map.put("GET_IMAGE_PREVIEW_PAGE", STATIC_RESOURCES_URL + GET_IMAGE_PREVIEW_PAGE);
176+
map.put("GET_IMAGE_PAGE", STATIC_RESOURCES_URL + ImageUrl.GET_IMAGE_PAGE);
177+
// CheckStyle: ignore LineLength for next 1 line
178+
map.put("GET_IMAGE_PREVIEW_PAGE", STATIC_RESOURCES_URL + ImageUrl.GET_IMAGE_PREVIEW_PAGE);
180179
map.put("MAIN_CSS", STATIC_RESOURCES_URL + MAIN_CSS);
181180
map.put("PARTICIPANT_ADD_JS", STATIC_RESOURCES_URL + PARTICIPANT_ADD_JS);
182181
map.put("SERIES_ADD_JS", STATIC_RESOURCES_URL + SERIES_ADD_JS);

src/main/java/ru/mystamps/web/feature/image/ImageController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.springframework.stereotype.Controller;
2222
import org.springframework.web.bind.annotation.GetMapping;
2323
import org.springframework.web.bind.annotation.PathVariable;
24-
import ru.mystamps.web.Url;
2524

2625
import javax.servlet.http.HttpServletResponse;
2726
import java.io.IOException;
@@ -33,7 +32,7 @@ public class ImageController {
3332

3433
private final ImageService imageService;
3534

36-
@GetMapping(Url.GET_IMAGE_PAGE)
35+
@GetMapping(ImageUrl.GET_IMAGE_PAGE)
3736
public void getImage(@PathVariable("id") Integer imageId, HttpServletResponse response)
3837
throws IOException {
3938

@@ -55,7 +54,7 @@ public void getImage(@PathVariable("id") Integer imageId, HttpServletResponse re
5554
response.getOutputStream().write(image.getData());
5655
}
5756

58-
@GetMapping(Url.GET_IMAGE_PREVIEW_PAGE)
57+
@GetMapping(ImageUrl.GET_IMAGE_PREVIEW_PAGE)
5958
public void getImagePreview(@PathVariable("id") Integer imageId, HttpServletResponse response)
6059
throws IOException {
6160

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2009-2019 Slava Semushin <slava.semushin@gmail.com>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*/
18+
package ru.mystamps.web.feature.image;
19+
20+
/**
21+
* Image-related URLs.
22+
*
23+
* Should be used everywhere instead of hard-coded paths.
24+
*
25+
* @author Slava Semushin
26+
*/
27+
public final class ImageUrl {
28+
29+
public static final String GET_IMAGE_PAGE = "/image/{id}";
30+
public static final String GET_IMAGE_PREVIEW_PAGE = "/image/preview/{id}";
31+
32+
private ImageUrl() {
33+
}
34+
35+
}

0 commit comments

Comments
 (0)