Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 1baf7bb

Browse files
committed
add imageUrl field to ProductUpdateSpec and UpdateProductRequest; validate image URL in ProductDomainService
1 parent 734de50 commit 1baf7bb

4 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/main/java/com/zenfulcode/commercify/api/product/dto/request/UpdateProductRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
public record UpdateProductRequest(
66
String name,
77
String description,
8+
String imageUrl,
89
Integer stock,
910
Money price,
1011
Boolean active

src/main/java/com/zenfulcode/commercify/api/product/mapper/ProductDtoMapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public UpdateProductCommand toCommand(ProductId productId, UpdateProductRequest
4848
ProductUpdateSpec updateSpec = new ProductUpdateSpec(
4949
request.name(),
5050
request.description(),
51+
request.imageUrl(),
5152
request.stock(),
5253
request.price(),
5354
request.active()

src/main/java/com/zenfulcode/commercify/product/domain/service/ProductDomainService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@ public void updateProduct(Product product, ProductUpdateSpec updateSpec) {
186186
}
187187
}
188188

189+
if (updateSpec.hasImageUrlUpdate()) {
190+
if (updateSpec.imageUrl() == null || updateSpec.imageUrl().isBlank()) {
191+
violations.add("Image URL cannot be empty");
192+
} else {
193+
// TODO: Validate image URL format
194+
product.setImageUrl(updateSpec.imageUrl());
195+
}
196+
}
197+
189198
// If there are any violations, throw an exception
190199
if (!violations.isEmpty()) {
191200
throw new ProductValidationException(violations);

src/main/java/com/zenfulcode/commercify/product/domain/valueobject/ProductUpdateSpec.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
public record ProductUpdateSpec(
66
String name,
77
String description,
8+
String imageUrl,
89
Integer stock,
910
Money price,
1011
Boolean active
@@ -28,4 +29,8 @@ public boolean hasPriceUpdate() {
2829
public boolean hasActiveUpdate() {
2930
return active != null;
3031
}
32+
33+
public boolean hasImageUrlUpdate() {
34+
return imageUrl != null;
35+
}
3136
}

0 commit comments

Comments
 (0)