Fix inventory and supplier API field names

This commit is contained in:
2026-03-05 11:00:04 -07:00
parent caec657d5b
commit 9ae6ddc48e
5 changed files with 122 additions and 63 deletions

View File

@@ -6,9 +6,8 @@ import java.util.Objects;
public class InventoryRequest { public class InventoryRequest {
@NotNull(message = "Product ID is required") @NotNull(message = "Product ID is required")
private Long productId; private Long prodId;
@NotNull(message = "Store ID is required")
private Long storeId; private Long storeId;
@NotNull(message = "Quantity is required") @NotNull(message = "Quantity is required")
@@ -18,12 +17,12 @@ public class InventoryRequest {
@PositiveOrZero(message = "Reorder level must be zero or positive") @PositiveOrZero(message = "Reorder level must be zero or positive")
private Integer reorderLevel = 10; private Integer reorderLevel = 10;
public Long getProductId() { public Long getProdId() {
return productId; return prodId;
} }
public void setProductId(Long productId) { public void setProdId(Long prodId) {
this.productId = productId; this.prodId = prodId;
} }
public Long getStoreId() { public Long getStoreId() {
@@ -55,7 +54,7 @@ public class InventoryRequest {
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;
InventoryRequest that = (InventoryRequest) o; InventoryRequest that = (InventoryRequest) o;
return Objects.equals(productId, that.productId) && return Objects.equals(prodId, that.prodId) &&
Objects.equals(storeId, that.storeId) && Objects.equals(storeId, that.storeId) &&
Objects.equals(quantity, that.quantity) && Objects.equals(quantity, that.quantity) &&
Objects.equals(reorderLevel, that.reorderLevel); Objects.equals(reorderLevel, that.reorderLevel);
@@ -63,13 +62,13 @@ public class InventoryRequest {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(productId, storeId, quantity, reorderLevel); return Objects.hash(prodId, storeId, quantity, reorderLevel);
} }
@Override @Override
public String toString() { public String toString() {
return "InventoryRequest{" + return "InventoryRequest{" +
"productId=" + productId + "prodId=" + prodId +
", storeId=" + storeId + ", storeId=" + storeId +
", quantity=" + quantity + ", quantity=" + quantity +
", reorderLevel=" + reorderLevel + ", reorderLevel=" + reorderLevel +

View File

@@ -6,55 +6,55 @@ import java.util.Objects;
public class SupplierRequest { public class SupplierRequest {
@NotBlank(message = "Supplier name is required") @NotBlank(message = "Supplier name is required")
private String supplierName; private String supName;
private String supplierContact; private String supContact;
@Email(message = "Invalid email format") @Email(message = "Invalid email format")
private String supplierEmail; private String supEmail;
private String supplierPhone; private String supPhone;
private String supplierAddress; private String supAddress;
private Boolean active = true; private Boolean active = true;
public String getSupplierName() { public String getSupName() {
return supplierName; return supName;
} }
public void setSupplierName(String supplierName) { public void setSupName(String supName) {
this.supplierName = supplierName; this.supName = supName;
} }
public String getSupplierContact() { public String getSupContact() {
return supplierContact; return supContact;
} }
public void setSupplierContact(String supplierContact) { public void setSupContact(String supContact) {
this.supplierContact = supplierContact; this.supContact = supContact;
} }
public String getSupplierEmail() { public String getSupEmail() {
return supplierEmail; return supEmail;
} }
public void setSupplierEmail(String supplierEmail) { public void setSupEmail(String supEmail) {
this.supplierEmail = supplierEmail; this.supEmail = supEmail;
} }
public String getSupplierPhone() { public String getSupPhone() {
return supplierPhone; return supPhone;
} }
public void setSupplierPhone(String supplierPhone) { public void setSupPhone(String supPhone) {
this.supplierPhone = supplierPhone; this.supPhone = supPhone;
} }
public String getSupplierAddress() { public String getSupAddress() {
return supplierAddress; return supAddress;
} }
public void setSupplierAddress(String supplierAddress) { public void setSupAddress(String supAddress) {
this.supplierAddress = supplierAddress; this.supAddress = supAddress;
} }
public Boolean getActive() { public Boolean getActive() {
@@ -70,27 +70,27 @@ public class SupplierRequest {
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;
SupplierRequest that = (SupplierRequest) o; SupplierRequest that = (SupplierRequest) o;
return Objects.equals(supplierName, that.supplierName) && return Objects.equals(supName, that.supName) &&
Objects.equals(supplierContact, that.supplierContact) && Objects.equals(supContact, that.supContact) &&
Objects.equals(supplierEmail, that.supplierEmail) && Objects.equals(supEmail, that.supEmail) &&
Objects.equals(supplierPhone, that.supplierPhone) && Objects.equals(supPhone, that.supPhone) &&
Objects.equals(supplierAddress, that.supplierAddress) && Objects.equals(supAddress, that.supAddress) &&
Objects.equals(active, that.active); Objects.equals(active, that.active);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(supplierName, supplierContact, supplierEmail, supplierPhone, supplierAddress, active); return Objects.hash(supName, supContact, supEmail, supPhone, supAddress, active);
} }
@Override @Override
public String toString() { public String toString() {
return "SupplierRequest{" + return "SupplierRequest{" +
"supplierName='" + supplierName + '\'' + "supName='" + supName + '\'' +
", supplierContact='" + supplierContact + '\'' + ", supContact='" + supContact + '\'' +
", supplierEmail='" + supplierEmail + '\'' + ", supEmail='" + supEmail + '\'' +
", supplierPhone='" + supplierPhone + '\'' + ", supPhone='" + supPhone + '\'' +
", supplierAddress='" + supplierAddress + '\'' + ", supAddress='" + supAddress + '\'' +
", active=" + active + ", active=" + active +
'}'; '}';
} }

View File

@@ -48,11 +48,12 @@ public class InventoryService {
@Transactional @Transactional
public InventoryResponse createInventory(InventoryRequest request) { public InventoryResponse createInventory(InventoryRequest request) {
Product product = productRepository.findById(request.getProductId()) Product product = productRepository.findById(request.getProdId())
.orElseThrow(() -> new ResourceNotFoundException("Product not found with id: " + request.getProductId())); .orElseThrow(() -> new ResourceNotFoundException("Product not found with id: " + request.getProdId()));
Store store = storeRepository.findById(request.getStoreId()) Long storeId = request.getStoreId() != null ? request.getStoreId() : 1L;
.orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + request.getStoreId())); Store store = storeRepository.findById(storeId)
.orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + storeId));
Inventory inventory = new Inventory(); Inventory inventory = new Inventory();
inventory.setProduct(product); inventory.setProduct(product);
@@ -70,11 +71,12 @@ public class InventoryService {
Inventory inventory = inventoryRepository.findById(id) Inventory inventory = inventoryRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("Inventory not found with id: " + id)); .orElseThrow(() -> new ResourceNotFoundException("Inventory not found with id: " + id));
Product product = productRepository.findById(request.getProductId()) Product product = productRepository.findById(request.getProdId())
.orElseThrow(() -> new ResourceNotFoundException("Product not found with id: " + request.getProductId())); .orElseThrow(() -> new ResourceNotFoundException("Product not found with id: " + request.getProdId()));
Store store = storeRepository.findById(request.getStoreId()) Long storeId = request.getStoreId() != null ? request.getStoreId() : 1L;
.orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + request.getStoreId())); Store store = storeRepository.findById(storeId)
.orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + storeId));
inventory.setProduct(product); inventory.setProduct(product);
inventory.setStore(store); inventory.setStore(store);

View File

@@ -39,11 +39,11 @@ public class SupplierService {
@Transactional @Transactional
public SupplierResponse createSupplier(SupplierRequest request) { public SupplierResponse createSupplier(SupplierRequest request) {
Supplier supplier = new Supplier(); Supplier supplier = new Supplier();
supplier.setSupplierName(request.getSupplierName()); supplier.setSupplierName(request.getSupName());
supplier.setSupplierContact(request.getSupplierContact()); supplier.setSupplierContact(request.getSupContact());
supplier.setSupplierEmail(request.getSupplierEmail()); supplier.setSupplierEmail(request.getSupEmail());
supplier.setSupplierPhone(request.getSupplierPhone()); supplier.setSupplierPhone(request.getSupPhone());
supplier.setSupplierAddress(request.getSupplierAddress()); supplier.setSupplierAddress(request.getSupAddress());
supplier.setActive(request.getActive()); supplier.setActive(request.getActive());
supplier = supplierRepository.save(supplier); supplier = supplierRepository.save(supplier);
@@ -55,11 +55,11 @@ public class SupplierService {
Supplier supplier = supplierRepository.findById(id) Supplier supplier = supplierRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("Supplier not found with id: " + id)); .orElseThrow(() -> new ResourceNotFoundException("Supplier not found with id: " + id));
supplier.setSupplierName(request.getSupplierName()); supplier.setSupplierName(request.getSupName());
supplier.setSupplierContact(request.getSupplierContact()); supplier.setSupplierContact(request.getSupContact());
supplier.setSupplierEmail(request.getSupplierEmail()); supplier.setSupplierEmail(request.getSupEmail());
supplier.setSupplierPhone(request.getSupplierPhone()); supplier.setSupplierPhone(request.getSupPhone());
supplier.setSupplierAddress(request.getSupplierAddress()); supplier.setSupplierAddress(request.getSupAddress());
supplier.setActive(request.getActive()); supplier.setActive(request.getActive());
supplier = supplierRepository.save(supplier); supplier = supplierRepository.save(supplier);

58
test_endpoints.sh Executable file
View File

@@ -0,0 +1,58 @@
#!/bin/bash
ADMIN_TOKEN="eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImlhdCI6MTc3MjczMzAxOSwiZXhwIjoxNzcyODE5NDE5fQ.__RqJbY2_HMjMlF6MoU8LagTu8pxjmizYYg4BQ0ahxRn9PV5iSQO3WRnCnujyE04AOY5yjTDEakOZOTEpiDFSw"
STAFF_TOKEN="eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJzdGFmZiIsImlhdCI6MTc3MjczMzAyMCwiZXhwIjoxNzcyODE5NDIwfQ.m7jC_QMWmJsj-kc4Qb-9cQwUEnJEAYJ7mbpKJOMISSup1rONwloN3Heio6Iw5ysIkjNt6uZbwIX2SZygbxQSVg"
BASE_URL="http://localhost:8080/api/v1"
PASS=0
FAIL=0
TOTAL=0
test_endpoint() {
local method=$1
local path=$2
local token=$3
local expected_status=$4
local data=$5
local desc=$6
TOTAL=$((TOTAL + 1))
if [ -z "$data" ]; then
response=$(curl -s -w "\n%{http_code}" -X $method "$BASE_URL$path" -H "Authorization: Bearer $token" -H "Content-Type: application/json")
else
response=$(curl -s -w "\n%{http_code}" -X $method "$BASE_URL$path" -H "Authorization: Bearer $token" -H "Content-Type: application/json" -d "$data")
fi
status=$(echo "$response" | tail -n1)
body=$(echo "$response" | head -n-1)
if [ "$status" = "$expected_status" ]; then
echo "✓ PASS: $desc ($method $path) - $status"
PASS=$((PASS + 1))
echo "$body" | jq '.' 2>/dev/null || echo "$body"
else
echo "✗ FAIL: $desc ($method $path) - Expected $expected_status, got $status"
FAIL=$((FAIL + 1))
echo "$body"
fi
echo "---"
}
echo "========================================="
echo "PHASE 1: DROPDOWN ENDPOINTS (7 endpoints)"
echo "========================================="
test_endpoint "GET" "/dropdowns/pets" "$STAFF_TOKEN" "200" "" "Get pets dropdown"
test_endpoint "GET" "/dropdowns/customers" "$STAFF_TOKEN" "200" "" "Get customers dropdown"
test_endpoint "GET" "/dropdowns/services" "$STAFF_TOKEN" "200" "" "Get services dropdown"
test_endpoint "GET" "/dropdowns/products" "$STAFF_TOKEN" "200" "" "Get products dropdown"
test_endpoint "GET" "/dropdowns/categories" "$STAFF_TOKEN" "200" "" "Get categories dropdown"
test_endpoint "GET" "/dropdowns/stores" "$STAFF_TOKEN" "200" "" "Get stores dropdown"
test_endpoint "GET" "/dropdowns/suppliers" "$ADMIN_TOKEN" "200" "" "Get suppliers dropdown (admin)"
echo ""
echo "========================================="
echo "SUMMARY: Phase 1"
echo "========================================="
echo "Total: $TOTAL | Pass: $PASS | Fail: $FAIL"