Skip to content

Commit eb35a58

Browse files
committed
task: rewrite AddCatalogNumbersForm to HTMX
Closes #1488 Part of #1671
1 parent 6315235 commit eb35a58

File tree

9 files changed

+171
-223
lines changed

9 files changed

+171
-223
lines changed

src/main/frontend/src/components/AddCatalogNumbersForm.js

-172
This file was deleted.

src/main/frontend/webpack.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module.exports = {
88
'utils/CatalogUtils': './src/utils/CatalogUtils.js',
99
'utils/DateUtils': './src/utils/DateUtils.js',
1010

11-
'components/AddCatalogNumbersForm': './src/components/AddCatalogNumbersForm.js',
1211
'components/AddCatalogPriceForm': './src/components/AddCatalogPriceForm.js',
1312
'components/AddReleaseYearForm': './src/components/AddReleaseYearForm.js',
1413
'components/HideImageForm': './src/components/HideImageForm.js',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (C) 2009-2025 Slava Semushin <[email protected]>
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+
19+
package ru.mystamps.web.feature.series;
20+
21+
import lombok.Getter;
22+
import lombok.Setter;
23+
24+
import javax.validation.constraints.NotBlank;
25+
import javax.validation.constraints.NotNull;
26+
27+
@Getter
28+
@Setter
29+
public class AddCatalogNumbersForm {
30+
@NotNull
31+
private StampsCatalog catalogName;
32+
33+
// @todo #1339 Update series: add validation for catalog numbers
34+
@NotBlank
35+
private String catalogNumbers;
36+
}

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

+50-1
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@ public class HtmxSeriesController {
4242
private final SeriesService seriesService;
4343

4444
@InitBinder("addCommentForm")
45-
protected void initBinder(WebDataBinder binder) {
45+
protected void initBinderForComments(WebDataBinder binder) {
4646
binder.registerCustomEditor(String.class, "comment", new StringTrimmerEditor(true));
4747
}
4848

49+
@InitBinder("addCatalogNumbersForm")
50+
protected void initBinderForCatalogNumbers(WebDataBinder binder) {
51+
binder.registerCustomEditor(String.class, "catalogNumbers", new StringTrimmerEditor(true));
52+
}
53+
4954
@PatchMapping(
5055
path = SeriesUrl.INFO_SERIES_PAGE,
5156
headers = "HX-Trigger=add-comment-form"
@@ -83,5 +88,49 @@ public String updateSeriesComment(
8388
model.addAttribute("comment", comment);
8489
return "series/partial/comment";
8590
}
91+
92+
@PatchMapping(
93+
path = SeriesUrl.INFO_SERIES_PAGE,
94+
headers = "HX-Trigger=add-catalog-numbers-form"
95+
)
96+
public String addCatalogNumbers(
97+
@PathVariable("id") Integer seriesId,
98+
@Valid AddCatalogNumbersForm form,
99+
BindingResult result,
100+
@AuthenticationPrincipal CustomUserDetails currentUser,
101+
Model model,
102+
HttpServletResponse response
103+
) throws IOException {
104+
105+
if (seriesId == null) {
106+
response.sendError(HttpServletResponse.SC_NOT_FOUND);
107+
return null;
108+
}
109+
110+
if (!seriesService.isSeriesExist(seriesId)) {
111+
response.sendError(HttpServletResponse.SC_NOT_FOUND);
112+
return null;
113+
}
114+
115+
if (result.hasErrors()) {
116+
response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
117+
model.addAttribute("isHtmx", true);
118+
model.addAttribute("seriesId", seriesId);
119+
return "series/info :: AddCatalogNumbersForm";
120+
}
121+
122+
Integer currentUserId = currentUser.getUserId();
123+
seriesService.addCatalogNumbers(
124+
form.getCatalogName(),
125+
seriesId,
126+
form.getCatalogNumbers(),
127+
currentUserId
128+
);
129+
130+
// @todo #1671 AddCatalogNumbersForm: update a page without full reload
131+
response.addHeader("HX-Refresh", "true");
132+
133+
return null;
134+
}
86135

87136
}

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

-14
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class RestSeriesController {
4646
private final SeriesService seriesService;
4747
private final SeriesImageService seriesImageService;
4848

49-
// @todo #1339 Update series: add validation for catalog numbers
5049
// @todo #1340 Update series: add validation for a price
5150
// @todo #1343 Update series: add validation for a release year
5251
@PatchMapping(SeriesUrl.INFO_SERIES_PAGE)
@@ -91,19 +90,6 @@ public ResponseEntity<Void> updateSeries(
9190
currentUserId
9291
);
9392
break;
94-
case "/michel_numbers":
95-
case "/scott_numbers":
96-
case "/yvert_numbers":
97-
case "/gibbons_numbers":
98-
case "/solovyov_numbers":
99-
case "/zagorski_numbers":
100-
seriesService.addCatalogNumbers(
101-
extractCatalog(path),
102-
seriesId,
103-
patch.getValue(),
104-
currentUserId
105-
);
106-
break;
10793
default:
10894
// @todo #785 Update series: properly fail on invalid path
10995
break;

src/main/java/ru/mystamps/web/feature/site/ResourceUrl.java

-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public final class ResourceUrl {
4343
private static final String SALE_IMPORT_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/SeriesSaleImportForm.min.js";
4444
private static final String SIMILAR_SERIES_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/SimilarSeriesForm.min.js";
4545
private static final String CATALOG_PRICE_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddCatalogPriceForm.min.js";
46-
private static final String CATALOG_NUMBERS_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddCatalogNumbersForm.min.js";
4746
private static final String RELEASE_YEAR_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddReleaseYearForm.min.js";
4847
private static final String HIDE_IMAGE_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/HideImageForm.min.js";
4948
private static final String SERIES_SALES_LIST_JS = "/public/js/" + RESOURCES_VERSION + "/components/SeriesSalesList.min.js";
@@ -83,7 +82,6 @@ public static void exposeResourcesToView(Map<String, String> resources, String h
8382
put(resources, host, "SALE_IMPORT_FORM_JS", SALE_IMPORT_FORM_JS);
8483
put(resources, host, "SIMILAR_SERIES_FORM_JS", SIMILAR_SERIES_FORM_JS);
8584
put(resources, host, "CATALOG_PRICE_FORM_JS", CATALOG_PRICE_FORM_JS);
86-
put(resources, host, "CATALOG_NUMBERS_FORM_JS", CATALOG_NUMBERS_FORM_JS);
8785
put(resources, host, "RELEASE_YEAR_FORM_JS", RELEASE_YEAR_FORM_JS);
8886
put(resources, host, "HIDE_IMAGE_FORM_JS", HIDE_IMAGE_FORM_JS);
8987
put(resources, host, "SERIES_SALES_LIST_JS", SERIES_SALES_LIST_JS);

src/main/resources/ru/mystamps/i18n/Messages.properties

+1-3
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ t_similar_series = Similar series
173173
t_mark_as_similar = Mark as similar
174174
t_could_not_import_info = Could not import information from this page
175175
t_comment = Comment
176+
t_numbers = Numbers
176177

177178
# category/info.html
178179
t_category_info = Category info
@@ -231,6 +232,3 @@ t_seller_group = Seller group
231232
# series/import/list.html
232233
t_no_import_requests = No import requests
233234
t_import_requests = import requests
234-
235-
# AddCatalogNumbersForm.js
236-
t_numbers = Numbers

src/main/resources/ru/mystamps/i18n/Messages_ru.properties

+1-3
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ t_similar_series = Похожие серии
172172
t_mark_as_similar = Отметить как похожую
173173
t_could_not_import_info = Не удалось импортировать информацию с этой страницы
174174
t_comment = Комментарий
175+
t_numbers = Номера
175176

176177
# category/info.html
177178
t_category_info = Информация о категории
@@ -230,6 +231,3 @@ t_seller_group = Группа продавца
230231
# series/import/list.html
231232
t_no_import_requests = Нет запросов на импорт
232233
t_import_requests = запросы на импорт
233-
234-
# AddCatalogNumbersForm.js
235-
t_numbers = Номера

0 commit comments

Comments
 (0)