diff --git a/src/main/java/com/petshop/backend/dto/inventory/InventoryRequest.java b/src/main/java/com/petshop/backend/dto/inventory/InventoryRequest.java index 947b7517..5ecf211a 100644 --- a/src/main/java/com/petshop/backend/dto/inventory/InventoryRequest.java +++ b/src/main/java/com/petshop/backend/dto/inventory/InventoryRequest.java @@ -6,9 +6,8 @@ import java.util.Objects; public class InventoryRequest { @NotNull(message = "Product ID is required") - private Long productId; + private Long prodId; - @NotNull(message = "Store ID is required") private Long storeId; @NotNull(message = "Quantity is required") @@ -18,12 +17,12 @@ public class InventoryRequest { @PositiveOrZero(message = "Reorder level must be zero or positive") private Integer reorderLevel = 10; - public Long getProductId() { - return productId; + public Long getProdId() { + return prodId; } - public void setProductId(Long productId) { - this.productId = productId; + public void setProdId(Long prodId) { + this.prodId = prodId; } public Long getStoreId() { @@ -55,7 +54,7 @@ public class InventoryRequest { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; InventoryRequest that = (InventoryRequest) o; - return Objects.equals(productId, that.productId) && + return Objects.equals(prodId, that.prodId) && Objects.equals(storeId, that.storeId) && Objects.equals(quantity, that.quantity) && Objects.equals(reorderLevel, that.reorderLevel); @@ -63,13 +62,13 @@ public class InventoryRequest { @Override public int hashCode() { - return Objects.hash(productId, storeId, quantity, reorderLevel); + return Objects.hash(prodId, storeId, quantity, reorderLevel); } @Override public String toString() { return "InventoryRequest{" + - "productId=" + productId + + "prodId=" + prodId + ", storeId=" + storeId + ", quantity=" + quantity + ", reorderLevel=" + reorderLevel + diff --git a/src/main/java/com/petshop/backend/dto/supplier/SupplierRequest.java b/src/main/java/com/petshop/backend/dto/supplier/SupplierRequest.java index 99fbe478..f7881ffa 100644 --- a/src/main/java/com/petshop/backend/dto/supplier/SupplierRequest.java +++ b/src/main/java/com/petshop/backend/dto/supplier/SupplierRequest.java @@ -6,55 +6,55 @@ import java.util.Objects; public class SupplierRequest { @NotBlank(message = "Supplier name is required") - private String supplierName; + private String supName; - private String supplierContact; + private String supContact; @Email(message = "Invalid email format") - private String supplierEmail; + private String supEmail; - private String supplierPhone; - private String supplierAddress; + private String supPhone; + private String supAddress; private Boolean active = true; - public String getSupplierName() { - return supplierName; + public String getSupName() { + return supName; } - public void setSupplierName(String supplierName) { - this.supplierName = supplierName; + public void setSupName(String supName) { + this.supName = supName; } - public String getSupplierContact() { - return supplierContact; + public String getSupContact() { + return supContact; } - public void setSupplierContact(String supplierContact) { - this.supplierContact = supplierContact; + public void setSupContact(String supContact) { + this.supContact = supContact; } - public String getSupplierEmail() { - return supplierEmail; + public String getSupEmail() { + return supEmail; } - public void setSupplierEmail(String supplierEmail) { - this.supplierEmail = supplierEmail; + public void setSupEmail(String supEmail) { + this.supEmail = supEmail; } - public String getSupplierPhone() { - return supplierPhone; + public String getSupPhone() { + return supPhone; } - public void setSupplierPhone(String supplierPhone) { - this.supplierPhone = supplierPhone; + public void setSupPhone(String supPhone) { + this.supPhone = supPhone; } - public String getSupplierAddress() { - return supplierAddress; + public String getSupAddress() { + return supAddress; } - public void setSupplierAddress(String supplierAddress) { - this.supplierAddress = supplierAddress; + public void setSupAddress(String supAddress) { + this.supAddress = supAddress; } public Boolean getActive() { @@ -70,27 +70,27 @@ public class SupplierRequest { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; SupplierRequest that = (SupplierRequest) o; - return Objects.equals(supplierName, that.supplierName) && - Objects.equals(supplierContact, that.supplierContact) && - Objects.equals(supplierEmail, that.supplierEmail) && - Objects.equals(supplierPhone, that.supplierPhone) && - Objects.equals(supplierAddress, that.supplierAddress) && + return Objects.equals(supName, that.supName) && + Objects.equals(supContact, that.supContact) && + Objects.equals(supEmail, that.supEmail) && + Objects.equals(supPhone, that.supPhone) && + Objects.equals(supAddress, that.supAddress) && Objects.equals(active, that.active); } @Override public int hashCode() { - return Objects.hash(supplierName, supplierContact, supplierEmail, supplierPhone, supplierAddress, active); + return Objects.hash(supName, supContact, supEmail, supPhone, supAddress, active); } @Override public String toString() { return "SupplierRequest{" + - "supplierName='" + supplierName + '\'' + - ", supplierContact='" + supplierContact + '\'' + - ", supplierEmail='" + supplierEmail + '\'' + - ", supplierPhone='" + supplierPhone + '\'' + - ", supplierAddress='" + supplierAddress + '\'' + + "supName='" + supName + '\'' + + ", supContact='" + supContact + '\'' + + ", supEmail='" + supEmail + '\'' + + ", supPhone='" + supPhone + '\'' + + ", supAddress='" + supAddress + '\'' + ", active=" + active + '}'; } diff --git a/src/main/java/com/petshop/backend/service/InventoryService.java b/src/main/java/com/petshop/backend/service/InventoryService.java index 78509765..9b2b0fe6 100644 --- a/src/main/java/com/petshop/backend/service/InventoryService.java +++ b/src/main/java/com/petshop/backend/service/InventoryService.java @@ -48,11 +48,12 @@ public class InventoryService { @Transactional public InventoryResponse createInventory(InventoryRequest request) { - Product product = productRepository.findById(request.getProductId()) - .orElseThrow(() -> new ResourceNotFoundException("Product not found with id: " + request.getProductId())); + Product product = productRepository.findById(request.getProdId()) + .orElseThrow(() -> new ResourceNotFoundException("Product not found with id: " + request.getProdId())); - Store store = storeRepository.findById(request.getStoreId()) - .orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + request.getStoreId())); + Long storeId = request.getStoreId() != null ? request.getStoreId() : 1L; + Store store = storeRepository.findById(storeId) + .orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + storeId)); Inventory inventory = new Inventory(); inventory.setProduct(product); @@ -70,11 +71,12 @@ public class InventoryService { Inventory inventory = inventoryRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Inventory not found with id: " + id)); - Product product = productRepository.findById(request.getProductId()) - .orElseThrow(() -> new ResourceNotFoundException("Product not found with id: " + request.getProductId())); + Product product = productRepository.findById(request.getProdId()) + .orElseThrow(() -> new ResourceNotFoundException("Product not found with id: " + request.getProdId())); - Store store = storeRepository.findById(request.getStoreId()) - .orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + request.getStoreId())); + Long storeId = request.getStoreId() != null ? request.getStoreId() : 1L; + Store store = storeRepository.findById(storeId) + .orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + storeId)); inventory.setProduct(product); inventory.setStore(store); diff --git a/src/main/java/com/petshop/backend/service/SupplierService.java b/src/main/java/com/petshop/backend/service/SupplierService.java index c7cdefaa..b234b759 100644 --- a/src/main/java/com/petshop/backend/service/SupplierService.java +++ b/src/main/java/com/petshop/backend/service/SupplierService.java @@ -39,11 +39,11 @@ public class SupplierService { @Transactional public SupplierResponse createSupplier(SupplierRequest request) { Supplier supplier = new Supplier(); - supplier.setSupplierName(request.getSupplierName()); - supplier.setSupplierContact(request.getSupplierContact()); - supplier.setSupplierEmail(request.getSupplierEmail()); - supplier.setSupplierPhone(request.getSupplierPhone()); - supplier.setSupplierAddress(request.getSupplierAddress()); + supplier.setSupplierName(request.getSupName()); + supplier.setSupplierContact(request.getSupContact()); + supplier.setSupplierEmail(request.getSupEmail()); + supplier.setSupplierPhone(request.getSupPhone()); + supplier.setSupplierAddress(request.getSupAddress()); supplier.setActive(request.getActive()); supplier = supplierRepository.save(supplier); @@ -55,11 +55,11 @@ public class SupplierService { Supplier supplier = supplierRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Supplier not found with id: " + id)); - supplier.setSupplierName(request.getSupplierName()); - supplier.setSupplierContact(request.getSupplierContact()); - supplier.setSupplierEmail(request.getSupplierEmail()); - supplier.setSupplierPhone(request.getSupplierPhone()); - supplier.setSupplierAddress(request.getSupplierAddress()); + supplier.setSupplierName(request.getSupName()); + supplier.setSupplierContact(request.getSupContact()); + supplier.setSupplierEmail(request.getSupEmail()); + supplier.setSupplierPhone(request.getSupPhone()); + supplier.setSupplierAddress(request.getSupAddress()); supplier.setActive(request.getActive()); supplier = supplierRepository.save(supplier); diff --git a/test_endpoints.sh b/test_endpoints.sh new file mode 100755 index 00000000..d310bbe6 --- /dev/null +++ b/test_endpoints.sh @@ -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"