From 950df59b42751c0ff97a4311468e38d0342e87f9 Mon Sep 17 00:00:00 2001 From: "nhkhai@gmail.com" Date: Fri, 22 Mar 2024 03:18:05 +0800 Subject: [PATCH 1/2] Updated ER Diagram to change mobile_no to phone_no. Fixed variable type. --- .../Diagrams/Entity Relationship Diagram.md | 20 +++++++++---------- .../com/smartinventory/entities/Customer.java | 10 +++++----- .../exceptions/ProductNotFoundException.java | 2 +- .../exceptions/ReviewNotFoundException.java | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Documentation/Diagrams/Entity Relationship Diagram.md b/Documentation/Diagrams/Entity Relationship Diagram.md index 0c4fc68..cf7baef 100644 --- a/Documentation/Diagrams/Entity Relationship Diagram.md +++ b/Documentation/Diagrams/Entity Relationship Diagram.md @@ -7,19 +7,10 @@ erDiagram string country string address int postal_code - int mobile_number + int phone_number string email } - Review { - long id PK - string category - string review_content - int rating - long customer_id FK - long product_id FK - } - Product { long id PK string category @@ -29,6 +20,15 @@ erDiagram int stock_quantity } + Review { + long id PK + string category + string review_content + int rating + long customer_id FK + long product_id FK + } + Customer ||--O{ Review : "Has" Product ||--O{ Review : "Has" ``` diff --git a/src/main/java/sg/com/smartinventory/entities/Customer.java b/src/main/java/sg/com/smartinventory/entities/Customer.java index f550f0f..a63d46f 100644 --- a/src/main/java/sg/com/smartinventory/entities/Customer.java +++ b/src/main/java/sg/com/smartinventory/entities/Customer.java @@ -45,9 +45,9 @@ public class Customer { @Column(name = "postal_code") private int postalCode; - @Digits(fraction = 0, integer = 8, message = "Mobile no should be 8 digits. ") - @Column(name = "mobile_number") - private int mobileNumber; + @Digits(fraction = 0, integer = 8, message = "Phone no should be 8 digits. ") + @Column(name = "phone_number") + private int phoneNumber; @Email(message = "Email should be valid. ") @Column(name = "email") @@ -57,7 +57,7 @@ public Customer() { } // Define Constructor for DataLoader. - public Customer(String firstName, String lastName, String country, String address, int postalCode, int mobileNumber, + public Customer(String firstName, String lastName, String country, String address, int postalCode, int phoneNumber, String email) { this(); @@ -66,7 +66,7 @@ public Customer(String firstName, String lastName, String country, String addres this.country = country; this.address = address; this.postalCode = postalCode; - this.mobileNumber = mobileNumber; + this.phoneNumber = phoneNumber; this.email = email; } } \ No newline at end of file diff --git a/src/main/java/sg/com/smartinventory/exceptions/ProductNotFoundException.java b/src/main/java/sg/com/smartinventory/exceptions/ProductNotFoundException.java index 635259f..cf13813 100644 --- a/src/main/java/sg/com/smartinventory/exceptions/ProductNotFoundException.java +++ b/src/main/java/sg/com/smartinventory/exceptions/ProductNotFoundException.java @@ -1,7 +1,7 @@ package sg.com.smartinventory.exceptions; public class ProductNotFoundException extends RuntimeException { - public ProductNotFoundException(String id) { + public ProductNotFoundException(Long id) { super("Could not find product with id: " + id + ". "); } } \ No newline at end of file diff --git a/src/main/java/sg/com/smartinventory/exceptions/ReviewNotFoundException.java b/src/main/java/sg/com/smartinventory/exceptions/ReviewNotFoundException.java index a86d991..995ad62 100644 --- a/src/main/java/sg/com/smartinventory/exceptions/ReviewNotFoundException.java +++ b/src/main/java/sg/com/smartinventory/exceptions/ReviewNotFoundException.java @@ -1,7 +1,7 @@ package sg.com.smartinventory.exceptions; public class ReviewNotFoundException extends RuntimeException { - public ReviewNotFoundException(String id) { + public ReviewNotFoundException(Long id) { super("Could not find review with id: " + id + ". "); } } \ No newline at end of file From 1e38657a593bfc20cd58fc655facd816f68ba08b Mon Sep 17 00:00:00 2001 From: "nhkhai@gmail.com" Date: Fri, 22 Mar 2024 03:24:21 +0800 Subject: [PATCH 2/2] Fixed test cases affected by the updated ER Diagram. --- .../smartinventory/controllers/CustomerControllerTest.java | 2 +- .../sg/com/smartinventory/integration/IntegrationTest.java | 6 +++--- .../smartinventory/services/CustomerServiceImplTest.java | 2 +- .../java/sg/com/smartinventory/useCases/UseCaseTest.java | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/java/sg/com/smartinventory/controllers/CustomerControllerTest.java b/src/test/java/sg/com/smartinventory/controllers/CustomerControllerTest.java index 0fc7eb1..a3ab485 100644 --- a/src/test/java/sg/com/smartinventory/controllers/CustomerControllerTest.java +++ b/src/test/java/sg/com/smartinventory/controllers/CustomerControllerTest.java @@ -42,7 +42,7 @@ public void createCustomerTest() throws Exception { // Step 1: Create a Customer object Customer newCustomer = Customer.builder().firstName("Jackie").lastName("Chan").country("Hong Kong") - .address("123 HK St").postalCode(654321).mobileNumber(87654321) + .address("123 HK St").postalCode(654321).phoneNumber(87654321) .email("jackie.chan@example.com").build(); // Step 2: Convert the Java object to JSON using ObjectMapper. diff --git a/src/test/java/sg/com/smartinventory/integration/IntegrationTest.java b/src/test/java/sg/com/smartinventory/integration/IntegrationTest.java index 938208d..459c31b 100644 --- a/src/test/java/sg/com/smartinventory/integration/IntegrationTest.java +++ b/src/test/java/sg/com/smartinventory/integration/IntegrationTest.java @@ -48,7 +48,7 @@ public class IntegrationTest { public void createCustomerTest() { // 1. Setup. Customer testObject1 = Customer.builder().firstName("Jackie").lastName("Chan").country("Hong Kong") - .address("123 HK St").postalCode(654321).mobileNumber(87654321) + .address("123 HK St").postalCode(654321).phoneNumber(87654321) .email("jackie.chan@example.com").build(); // mock the save method of the customer repository @@ -69,10 +69,10 @@ public void createCustomerTest() { public void runIntegratedTest() throws Exception { // Step 1: Create the test objects. Customer testObject1 = Customer.builder().firstName("Jackie").lastName("Chan").country("Hong Kong") - .address("123 HK St").postalCode(654321).mobileNumber(87654321) + .address("123 HK St").postalCode(654321).phoneNumber(87654321) .email("jackie.chan@example.com").build(); Customer testObject2 = Customer.builder().firstName("Jackie").lastName("Chang").country("Hong Kong") - .address("123 HK St").postalCode(654321).mobileNumber(87654321) + .address("123 HK St").postalCode(654321).phoneNumber(87654321) .email("jackie.chang@example.com").build(); // Step 2: Convert the Java objects to JSON using ObjectMapper. diff --git a/src/test/java/sg/com/smartinventory/services/CustomerServiceImplTest.java b/src/test/java/sg/com/smartinventory/services/CustomerServiceImplTest.java index 3dcb4de..ebc57ea 100644 --- a/src/test/java/sg/com/smartinventory/services/CustomerServiceImplTest.java +++ b/src/test/java/sg/com/smartinventory/services/CustomerServiceImplTest.java @@ -31,7 +31,7 @@ public void createCustomerTest() { // 1. SETUP // Create a new customer. Customer customer = Customer.builder().firstName("John").lastName("Wick").country("USA").address("123 Main St") - .postalCode(123456).mobileNumber(12345678).email("john.wick@example.com").build(); + .postalCode(123456).phoneNumber(12345678).email("john.wick@example.com").build(); // Mock the save method of the customer repository. when((customerRepository.save(customer))).thenReturn(customer); diff --git a/src/test/java/sg/com/smartinventory/useCases/UseCaseTest.java b/src/test/java/sg/com/smartinventory/useCases/UseCaseTest.java index 2694b8b..3190eb4 100644 --- a/src/test/java/sg/com/smartinventory/useCases/UseCaseTest.java +++ b/src/test/java/sg/com/smartinventory/useCases/UseCaseTest.java @@ -48,7 +48,7 @@ public class UseCaseTest { public void createCustomerTest() { // 1. Setup. Customer testObject1 = Customer.builder().firstName("Jackie").lastName("Chan").country("Hong Kong") - .address("123 HK St").postalCode(654321).mobileNumber(87654321) + .address("123 HK St").postalCode(654321).phoneNumber(87654321) .email("jackie.chan@example.com").build(); // mock the save method of the customer repository @@ -69,10 +69,10 @@ public void createCustomerTest() { public void runIntegratedTest() throws Exception { // Step 1: Create the test objects. Customer testObject1 = Customer.builder().firstName("Jackie").lastName("Chan").country("Hong Kong") - .address("123 HK St").postalCode(654321).mobileNumber(87654321) + .address("123 HK St").postalCode(654321).phoneNumber(87654321) .email("jackie.chan@example.com").build(); Customer testObject2 = Customer.builder().firstName("Jackie").lastName("Chang").country("Hong Kong") - .address("123 HK St").postalCode(654321).mobileNumber(87654321) + .address("123 HK St").postalCode(654321).phoneNumber(87654321) .email("jackie.chang@example.com").build(); // Step 2: Convert the Java objects to JSON using ObjectMapper.