fix(front-end): improvements in load products by uuid truncated
Some checks failed
Build and Deploy / test-backend (push) Successful in 38s
Build and Deploy / test-frontend (push) Successful in 1m37s
Build and Deploy / build-and-push (push) Successful in 1m57s
Build and Deploy / deploy (push) Successful in 22s
PR Checks / prettier-autofix (pull_request) Failing after 13s
PR Checks / test-backend (pull_request) Successful in 28s
PR Checks / security-sast (pull_request) Successful in 40s
PR Checks / test-frontend (pull_request) Successful in 1m15s
Some checks failed
Build and Deploy / test-backend (push) Successful in 38s
Build and Deploy / test-frontend (push) Successful in 1m37s
Build and Deploy / build-and-push (push) Successful in 1m57s
Build and Deploy / deploy (push) Successful in 22s
PR Checks / prettier-autofix (pull_request) Failing after 13s
PR Checks / test-backend (pull_request) Successful in 28s
PR Checks / security-sast (pull_request) Successful in 40s
PR Checks / test-frontend (pull_request) Successful in 1m15s
This commit is contained in:
@@ -62,6 +62,12 @@ public class PublicShopController {
|
||||
return ResponseEntity.ok(publicShopCatalogService.getProductByPublicPath(publicPath, lang));
|
||||
}
|
||||
|
||||
@GetMapping("/products/by-id-prefix/{idPrefix}")
|
||||
public ResponseEntity<ShopProductDetailDto> getProductByIdPrefix(@PathVariable String idPrefix,
|
||||
@RequestParam(required = false) String lang) {
|
||||
return ResponseEntity.ok(publicShopCatalogService.getProductByIdPrefix(idPrefix, lang));
|
||||
}
|
||||
|
||||
@GetMapping("/products/{slug}/model")
|
||||
public ResponseEntity<Resource> getProductModel(@PathVariable String slug) throws IOException {
|
||||
PublicShopCatalogService.ProductModelDownload model = publicShopCatalogService.getProductModelDownload(slug);
|
||||
|
||||
@@ -163,6 +163,28 @@ public class PublicShopCatalogService {
|
||||
);
|
||||
}
|
||||
|
||||
public ShopProductDetailDto getProductByIdPrefix(String idPrefix, String language) {
|
||||
String normalizedLanguage = normalizeLanguage(language);
|
||||
String normalizedIdPrefix = normalizeProductIdPrefix(idPrefix);
|
||||
if (normalizedIdPrefix == null) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Product not found");
|
||||
}
|
||||
|
||||
CategoryContext categoryContext = loadCategoryContext(normalizedLanguage);
|
||||
PublicProductContext productContext = loadPublicProductContext(categoryContext, normalizedLanguage);
|
||||
ProductEntry entry = requirePublicProductEntry(
|
||||
productContext.entriesByIdPrefix().get(normalizedIdPrefix),
|
||||
categoryContext
|
||||
);
|
||||
|
||||
return toProductDetailDto(
|
||||
entry,
|
||||
productContext.productMediaBySlug(),
|
||||
productContext.variantColorHexByMaterialAndColor(),
|
||||
normalizedLanguage
|
||||
);
|
||||
}
|
||||
|
||||
public ProductModelDownload getProductModelDownload(String slug) {
|
||||
CategoryContext categoryContext = loadCategoryContext(null);
|
||||
PublicProductContext productContext = loadPublicProductContext(categoryContext, null);
|
||||
@@ -231,11 +253,19 @@ public class PublicShopCatalogService {
|
||||
(left, right) -> left,
|
||||
LinkedHashMap::new
|
||||
));
|
||||
Map<String, ProductEntry> entriesByIdPrefix = entries.stream()
|
||||
.collect(Collectors.toMap(
|
||||
entry -> normalizeProductIdPrefix(ShopPublicPathSupport.productIdPrefix(entry.product().getId())),
|
||||
entry -> entry,
|
||||
(left, right) -> left,
|
||||
LinkedHashMap::new
|
||||
));
|
||||
|
||||
return new PublicProductContext(
|
||||
entries,
|
||||
entriesBySlug,
|
||||
entriesByPublicPath,
|
||||
entriesByIdPrefix,
|
||||
productMediaBySlug,
|
||||
variantColorHexByMaterialAndColor
|
||||
);
|
||||
@@ -566,6 +596,15 @@ public class PublicShopCatalogService {
|
||||
return normalized.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private String normalizeProductIdPrefix(String idPrefix) {
|
||||
String normalized = trimToNull(idPrefix);
|
||||
if (normalized == null) {
|
||||
return null;
|
||||
}
|
||||
normalized = normalized.toLowerCase(Locale.ROOT);
|
||||
return normalized.matches("^[0-9a-f]{8}$") ? normalized : null;
|
||||
}
|
||||
|
||||
private String trimToNull(String value) {
|
||||
String raw = String.valueOf(value == null ? "" : value).trim();
|
||||
if (raw.isEmpty()) {
|
||||
@@ -662,6 +701,7 @@ public class PublicShopCatalogService {
|
||||
List<ProductEntry> entries,
|
||||
Map<String, ProductEntry> entriesBySlug,
|
||||
Map<String, ProductEntry> entriesByPublicPath,
|
||||
Map<String, ProductEntry> entriesByIdPrefix,
|
||||
Map<String, List<PublicMediaUsageDto>> productMediaBySlug,
|
||||
Map<String, String> variantColorHexByMaterialAndColor
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user