Fix product API field names to match Postman

This commit is contained in:
2026-03-05 10:53:49 -07:00
parent d7fb057e64
commit caec657d5b
2 changed files with 28 additions and 28 deletions

View File

@@ -8,25 +8,25 @@ import java.util.Objects;
public class ProductRequest { public class ProductRequest {
@NotBlank(message = "Product name is required") @NotBlank(message = "Product name is required")
private String productName; private String prodName;
@NotNull(message = "Category ID is required") @NotNull(message = "Category ID is required")
private Long categoryId; private Long categoryId;
private String productDescription; private String prodDesc;
@NotNull(message = "Product price is required") @NotNull(message = "Product price is required")
@Positive(message = "Price must be positive") @Positive(message = "Price must be positive")
private BigDecimal productPrice; private BigDecimal prodPrice;
private Boolean active = true; private Boolean active = true;
public String getProductName() { public String getProdName() {
return productName; return prodName;
} }
public void setProductName(String productName) { public void setProdName(String prodName) {
this.productName = productName; this.prodName = prodName;
} }
public Long getCategoryId() { public Long getCategoryId() {
@@ -37,20 +37,20 @@ public class ProductRequest {
this.categoryId = categoryId; this.categoryId = categoryId;
} }
public String getProductDescription() { public String getProdDesc() {
return productDescription; return prodDesc;
} }
public void setProductDescription(String productDescription) { public void setProdDesc(String prodDesc) {
this.productDescription = productDescription; this.prodDesc = prodDesc;
} }
public BigDecimal getProductPrice() { public BigDecimal getProdPrice() {
return productPrice; return prodPrice;
} }
public void setProductPrice(BigDecimal productPrice) { public void setProdPrice(BigDecimal prodPrice) {
this.productPrice = productPrice; this.prodPrice = prodPrice;
} }
public Boolean getActive() { public Boolean getActive() {
@@ -66,25 +66,25 @@ public class ProductRequest {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
ProductRequest that = (ProductRequest) o; ProductRequest that = (ProductRequest) o;
return Objects.equals(productName, that.productName) && return Objects.equals(prodName, that.prodName) &&
Objects.equals(categoryId, that.categoryId) && Objects.equals(categoryId, that.categoryId) &&
Objects.equals(productDescription, that.productDescription) && Objects.equals(prodDesc, that.prodDesc) &&
Objects.equals(productPrice, that.productPrice) && Objects.equals(prodPrice, that.prodPrice) &&
Objects.equals(active, that.active); Objects.equals(active, that.active);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(productName, categoryId, productDescription, productPrice, active); return Objects.hash(prodName, categoryId, prodDesc, prodPrice, active);
} }
@Override @Override
public String toString() { public String toString() {
return "ProductRequest{" + return "ProductRequest{" +
"productName='" + productName + '\'' + "prodName='" + prodName + '\'' +
", categoryId=" + categoryId + ", categoryId=" + categoryId +
", productDescription='" + productDescription + '\'' + ", prodDesc='" + prodDesc + '\'' +
", productPrice=" + productPrice + ", prodPrice=" + prodPrice +
", active=" + active + ", active=" + active +
'}'; '}';
} }

View File

@@ -46,10 +46,10 @@ public class ProductService {
.orElseThrow(() -> new ResourceNotFoundException("Category not found with id: " + request.getCategoryId())); .orElseThrow(() -> new ResourceNotFoundException("Category not found with id: " + request.getCategoryId()));
Product product = new Product(); Product product = new Product();
product.setProductName(request.getProductName()); product.setProductName(request.getProdName());
product.setCategory(category); product.setCategory(category);
product.setProductDescription(request.getProductDescription()); product.setProductDescription(request.getProdDesc());
product.setProductPrice(request.getProductPrice()); product.setProductPrice(request.getProdPrice());
product.setActive(request.getActive() != null ? request.getActive() : true); product.setActive(request.getActive() != null ? request.getActive() : true);
product = productRepository.save(product); product = productRepository.save(product);
@@ -64,10 +64,10 @@ public class ProductService {
Category category = categoryRepository.findById(request.getCategoryId()) Category category = categoryRepository.findById(request.getCategoryId())
.orElseThrow(() -> new ResourceNotFoundException("Category not found with id: " + request.getCategoryId())); .orElseThrow(() -> new ResourceNotFoundException("Category not found with id: " + request.getCategoryId()));
product.setProductName(request.getProductName()); product.setProductName(request.getProdName());
product.setCategory(category); product.setCategory(category);
product.setProductDescription(request.getProductDescription()); product.setProductDescription(request.getProdDesc());
product.setProductPrice(request.getProductPrice()); product.setProductPrice(request.getProdPrice());
product.setActive(request.getActive() != null ? request.getActive() : true); product.setActive(request.getActive() != null ? request.getActive() : true);
product = productRepository.save(product); product = productRepository.save(product);