Skip to content

Commit 7126544

Browse files
committed
task: rewrite AddCatalogPriceForm to HTMX
Closes #1487 Part of #1671
1 parent afbf07b commit 7126544

File tree

10 files changed

+240
-257
lines changed

10 files changed

+240
-257
lines changed

src/main/frontend/src/components/AddCatalogPriceForm.js

Lines changed: 0 additions & 190 deletions
This file was deleted.

src/main/frontend/webpack.config.js

Lines changed: 0 additions & 1 deletion
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/AddCatalogPriceForm': './src/components/AddCatalogPriceForm.js',
1211
'components/AddReleaseYearForm': './src/components/AddReleaseYearForm.js',
1312
'components/HideImageForm': './src/components/HideImageForm.js',
1413
'components/SeriesSaleImportForm': './src/components/SeriesSaleImportForm.js',
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (C) 2009-2025 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+
19+
package ru.mystamps.web.feature.series;
20+
21+
import lombok.Getter;
22+
import lombok.Setter;
23+
24+
import javax.validation.constraints.NotNull;
25+
import java.math.BigDecimal;
26+
27+
@Getter
28+
@Setter
29+
public class AddCatalogPriceForm {
30+
@NotNull
31+
private StampsCatalog catalogName;
32+
33+
// @todo #1340 Update series: add validation for a price
34+
@NotNull
35+
private BigDecimal price;
36+
}

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,49 @@ public String addCatalogNumbers(
132132

133133
return null;
134134
}
135+
136+
@PatchMapping(
137+
path = SeriesUrl.INFO_SERIES_PAGE,
138+
headers = "HX-Trigger=add-catalog-price-form"
139+
)
140+
public String addCatalogPrice(
141+
@PathVariable("id") Integer seriesId,
142+
@Valid AddCatalogPriceForm form,
143+
BindingResult result,
144+
@AuthenticationPrincipal CustomUserDetails currentUser,
145+
Model model,
146+
HttpServletResponse response
147+
) throws IOException {
148+
149+
if (seriesId == null) {
150+
response.sendError(HttpServletResponse.SC_NOT_FOUND);
151+
return null;
152+
}
153+
154+
if (!seriesService.isSeriesExist(seriesId)) {
155+
response.sendError(HttpServletResponse.SC_NOT_FOUND);
156+
return null;
157+
}
158+
159+
if (result.hasErrors()) {
160+
response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
161+
model.addAttribute("isHtmx", true);
162+
model.addAttribute("seriesId", seriesId);
163+
return "series/info :: AddCatalogPriceForm";
164+
}
165+
166+
Integer currentUserId = currentUser.getUserId();
167+
seriesService.addCatalogPrice(
168+
form.getCatalogName(),
169+
seriesId,
170+
form.getPrice(),
171+
currentUserId
172+
);
173+
174+
// @todo #1671 AddCatalogPriceForm: update a page without full reload
175+
response.addHeader("HX-Refresh", "true");
176+
177+
return null;
178+
}
135179

136180
}

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

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package ru.mystamps.web.feature.series;
1919

2020
import lombok.RequiredArgsConstructor;
21-
import org.apache.commons.lang3.StringUtils;
2221
import org.springframework.http.ResponseEntity;
2322
import org.springframework.security.core.annotation.AuthenticationPrincipal;
2423
import org.springframework.validation.annotation.Validated;
@@ -36,7 +35,6 @@
3635
import javax.validation.constraints.NotEmpty;
3736
import java.io.IOException;
3837
import java.util.List;
39-
import java.util.Locale;
4038

4139
@Validated
4240
@RestController
@@ -46,7 +44,6 @@ class RestSeriesController {
4644
private final SeriesService seriesService;
4745
private final SeriesImageService seriesImageService;
4846

49-
// @todo #1340 Update series: add validation for a price
5047
// @todo #1343 Update series: add validation for a release year
5148
@PatchMapping(SeriesUrl.INFO_SERIES_PAGE)
5249
public ResponseEntity<Void> updateSeries(
@@ -77,19 +74,6 @@ public ResponseEntity<Void> updateSeries(
7774
case "/release_year":
7875
seriesService.addReleaseYear(seriesId, patch.integerValue(), currentUserId);
7976
break;
80-
case "/michel_price":
81-
case "/scott_price":
82-
case "/yvert_price":
83-
case "/gibbons_price":
84-
case "/solovyov_price":
85-
case "/zagorski_price":
86-
seriesService.addCatalogPrice(
87-
extractCatalog(path),
88-
seriesId,
89-
patch.bigDecimalValue(),
90-
currentUserId
91-
);
92-
break;
9377
default:
9478
// @todo #785 Update series: properly fail on invalid path
9579
break;
@@ -116,12 +100,5 @@ public ResponseEntity<Void> modifySeriesImage(
116100
return ResponseEntity.noContent().build();
117101
}
118102

119-
private static StampsCatalog extractCatalog(String path) {
120-
// "/catalog_something" => "catalog" => "CATALOG"
121-
String catalogName = StringUtils.substringBetween(path, "/", "_")
122-
.toUpperCase(Locale.ENGLISH);
123-
return StampsCatalog.valueOf(catalogName);
124-
}
125-
126103
}
127104

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@
1717
*/
1818
package ru.mystamps.web.feature.series;
1919

20+
import lombok.Getter;
21+
import lombok.RequiredArgsConstructor;
22+
23+
@Getter
24+
@RequiredArgsConstructor
2025
public enum StampsCatalog {
21-
MICHEL,
22-
SCOTT,
23-
YVERT,
24-
GIBBONS,
25-
SOLOVYOV,
26-
ZAGORSKI
26+
MICHEL("EUR", "\u20AC"),
27+
SCOTT("USD", "$"),
28+
YVERT("EUR", "\u20AC"),
29+
GIBBONS("GBP", "\u00A3"),
30+
SOLOVYOV("RUB", "\u20BD"),
31+
ZAGORSKI("RUB", "\u20BD");
32+
33+
private final String currencyCode;
34+
private final String currencySymbol;
2735
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public final class ResourceUrl {
3131
public static final String STATIC_RESOURCES_URL = "https://stamps.filezz.ru";
3232

3333
// MUST be updated when any of our resources were modified
34-
public static final String RESOURCES_VERSION = "v0.4.7.0";
34+
public static final String RESOURCES_VERSION = "v0.4.7.1";
3535

3636
private static final String CATALOG_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/utils/CatalogUtils.min.js";
3737
private static final String COLLECTION_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/collection/info.min.js";
@@ -42,7 +42,6 @@ public final class ResourceUrl {
4242
private static final String SERIES_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/series/info.min.js";
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";
45-
private static final String CATALOG_PRICE_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddCatalogPriceForm.min.js";
4645
private static final String RELEASE_YEAR_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddReleaseYearForm.min.js";
4746
private static final String HIDE_IMAGE_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/HideImageForm.min.js";
4847
private static final String SERIES_SALES_LIST_JS = "/public/js/" + RESOURCES_VERSION + "/components/SeriesSalesList.min.js";
@@ -81,7 +80,6 @@ public static void exposeResourcesToView(Map<String, String> resources, String h
8180
put(resources, host, "SERIES_INFO_JS", SERIES_INFO_JS);
8281
put(resources, host, "SALE_IMPORT_FORM_JS", SALE_IMPORT_FORM_JS);
8382
put(resources, host, "SIMILAR_SERIES_FORM_JS", SIMILAR_SERIES_FORM_JS);
84-
put(resources, host, "CATALOG_PRICE_FORM_JS", CATALOG_PRICE_FORM_JS);
8583
put(resources, host, "RELEASE_YEAR_FORM_JS", RELEASE_YEAR_FORM_JS);
8684
put(resources, host, "HIDE_IMAGE_FORM_JS", HIDE_IMAGE_FORM_JS);
8785
put(resources, host, "SERIES_SALES_LIST_JS", SERIES_SALES_LIST_JS);

0 commit comments

Comments
 (0)