Skip to content

Commit

Permalink
Update ProductVo -> ProductValueObject in catalog service
Browse files Browse the repository at this point in the history
  • Loading branch information
saragluna committed May 26, 2024
1 parent 93103a5 commit 709071e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

public class GetProductResponse {

private ProductVo data;
private ProductValueObject data;
private int status;

public GetProductResponse(ProductVo data, int status) {
public GetProductResponse(ProductValueObject data, int status) {
this.data = data;
this.status = status;
}

public ProductVo getData() {
public ProductValueObject getData() {
return data;
}

public void setData(ProductVo data) {
public void setData(ProductValueObject data) {
this.data = data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

public class GetProductsResponse {

private List<ProductVo> data;
private List<ProductValueObject> data;

public GetProductsResponse(List<ProductVo> data) {
public GetProductsResponse(List<ProductValueObject> data) {
this.data = data;
}

public List<ProductVo> getData() {
public List<ProductValueObject> getData() {
return data;
}

public void setData(List<ProductVo> data) {
public void setData(List<ProductValueObject> data) {
this.data = data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ public class Product {
private Double price;
private String tags;

public static Product fromProductRequestToProduct(ProductVo productVo) {
public static Product fromProductRequestToProduct(ProductValueObject productVO) {

Product product = new Product();
product.setPrice(productVo.getPrice());
product.setDescription(productVo.getDescription());
product.setName(productVo.getName());
product.setImageUrl1(productVo.getImageUrl1());
product.setImageUrl2(productVo.getImageUrl2());
product.setImageUrl3(productVo.getImageUrl3());
product.setShortDescription(productVo.getShortDescription());
product.setPrice(productVO.getPrice());
product.setDescription(productVO.getDescription());
product.setName(productVO.getName());
product.setImageUrl1(productVO.getImageUrl1());
product.setImageUrl2(productVO.getImageUrl2());
product.setImageUrl3(productVO.getImageUrl3());
product.setShortDescription(productVO.getShortDescription());

String tags = null;

if (productVo.getTags() != null && !productVo.getTags().isEmpty()) {
if (productVO.getTags() != null && !productVO.getTags().isEmpty()) {
tags = "";
for (int i = 0; i < productVo.getTags().size(); i++) {
tags = tags + productVo.getTags().get(i);
if (i < productVo.getTags().size() - 1) {
for (int i = 0; i < productVO.getTags().size(); i++) {
tags = tags + productVO.getTags().get(i);
if (i < productVO.getTags().size() - 1) {
tags = tags + ",";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ public ProductController(ProductService productService) {
@GetMapping("/products")
public GetProductsResponse getProducts() {
return new GetProductsResponse(productService.getProducts().stream()
.map(ProductVo::new)
.map(ProductValueObject::new)
.collect(Collectors.toList()));
}

@GetMapping("/products/{id}")
public GetProductResponse getProduct(@PathVariable String id) {
return new GetProductResponse(new ProductVo(productService.getProduct(id)), HttpStatus.OK.value());
return new GetProductResponse(new ProductValueObject(productService.getProduct(id)), HttpStatus.OK.value());
}

@PostMapping("/products")
public ResponseEntity<ProductVo> createProduct(@RequestBody ProductVo productVo) {
Product product = productService.createProduct(Product.fromProductRequestToProduct(productVo));
return ResponseEntity.ok(new ProductVo(product));
public ResponseEntity<ProductValueObject> createProduct(@RequestBody ProductValueObject productVO) {
Product product = productService.createProduct(Product.fromProductRequestToProduct(productVO));
return ResponseEntity.ok(new ProductValueObject(product));
}

@PostMapping("/products/{id}")
public ResponseEntity<ProductVo> updateProduct(@PathVariable String id, @RequestBody ProductVo productVo) {
Product product = productService.updateProduct(id, Product.fromProductRequestToProduct(productVo));
return ResponseEntity.ok(new ProductVo(product));
public ResponseEntity<ProductValueObject> updateProduct(@PathVariable String id, @RequestBody ProductValueObject productVO) {
Product product = productService.updateProduct(id, Product.fromProductRequestToProduct(productVO));
return ResponseEntity.ok(new ProductValueObject(product));
}

@DeleteMapping("/products/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import org.springframework.util.StringUtils;

public class ProductVo {
public class ProductValueObject {

private String id;
private String imageUrl1;
Expand All @@ -18,10 +18,10 @@ public class ProductVo {
private Double price;
private List<String> tags = new ArrayList<>();

public ProductVo() {
public ProductValueObject() {
}

public ProductVo(Product product) {
public ProductValueObject(Product product) {
id = product.getId();
price = product.getPrice();
description = product.getDescription();
Expand Down

0 comments on commit 709071e

Please sign in to comment.