From c48039eeb42cdd5e48800bb6af66ca1a931d6598 Mon Sep 17 00:00:00 2001 From: Harkamal Randhawa Date: Wed, 1 Apr 2026 18:08:37 -0600 Subject: [PATCH 1/2] Fix phone formatting --- .../petshop/backend/entity/StoreLocation.java | 3 +- .../com/petshop/backend/entity/Supplier.java | 3 +- .../java/com/petshop/backend/entity/User.java | 3 +- .../com/petshop/backend/util/PhoneUtils.java | 24 +++++++++++++ .../V14__normalize_phone_numbers.sql | 34 +++++++++++++++++++ 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 backend/src/main/java/com/petshop/backend/util/PhoneUtils.java create mode 100644 backend/src/main/resources/db/migration/V14__normalize_phone_numbers.sql diff --git a/backend/src/main/java/com/petshop/backend/entity/StoreLocation.java b/backend/src/main/java/com/petshop/backend/entity/StoreLocation.java index 6b1a2ced..8c6a9c76 100644 --- a/backend/src/main/java/com/petshop/backend/entity/StoreLocation.java +++ b/backend/src/main/java/com/petshop/backend/entity/StoreLocation.java @@ -1,5 +1,6 @@ package com.petshop.backend.entity; +import com.petshop.backend.util.PhoneUtils; import jakarta.persistence.*; import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.UpdateTimestamp; @@ -77,7 +78,7 @@ public class StoreLocation { } public void setPhone(String phone) { - this.phone = phone; + this.phone = PhoneUtils.normalize(phone); } public String getEmail() { diff --git a/backend/src/main/java/com/petshop/backend/entity/Supplier.java b/backend/src/main/java/com/petshop/backend/entity/Supplier.java index 5dc35f17..911aad08 100644 --- a/backend/src/main/java/com/petshop/backend/entity/Supplier.java +++ b/backend/src/main/java/com/petshop/backend/entity/Supplier.java @@ -1,5 +1,6 @@ package com.petshop.backend.entity; +import com.petshop.backend.util.PhoneUtils; import jakarta.persistence.*; import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.UpdateTimestamp; @@ -97,7 +98,7 @@ public class Supplier { } public void setSupPhone(String supPhone) { - this.supPhone = supPhone; + this.supPhone = PhoneUtils.normalize(supPhone); } public LocalDateTime getCreatedAt() { diff --git a/backend/src/main/java/com/petshop/backend/entity/User.java b/backend/src/main/java/com/petshop/backend/entity/User.java index cdec2754..d13e2e68 100644 --- a/backend/src/main/java/com/petshop/backend/entity/User.java +++ b/backend/src/main/java/com/petshop/backend/entity/User.java @@ -1,5 +1,6 @@ package com.petshop.backend.entity; +import com.petshop.backend.util.PhoneUtils; import jakarta.persistence.*; import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.UpdateTimestamp; @@ -118,7 +119,7 @@ public class User { } public void setPhone(String phone) { - this.phone = phone; + this.phone = PhoneUtils.normalize(phone); } public String getAvatarUrl() { diff --git a/backend/src/main/java/com/petshop/backend/util/PhoneUtils.java b/backend/src/main/java/com/petshop/backend/util/PhoneUtils.java new file mode 100644 index 00000000..cf9646ba --- /dev/null +++ b/backend/src/main/java/com/petshop/backend/util/PhoneUtils.java @@ -0,0 +1,24 @@ +package com.petshop.backend.util; + +public class PhoneUtils { + public static String normalize(String phone) { + if (phone == null) { + return null; + } + + String digits = phone.replaceAll("\\D", ""); + + if (digits.length() >= 10) { + if (digits.length() == 11 && digits.startsWith("1")) { + digits = digits.substring(1); + } + digits = digits.substring(0, 10); + return String.format("(%s) %s-%s", + digits.substring(0, 3), + digits.substring(3, 6), + digits.substring(6)); + } + + return phone; + } +} diff --git a/backend/src/main/resources/db/migration/V14__normalize_phone_numbers.sql b/backend/src/main/resources/db/migration/V14__normalize_phone_numbers.sql new file mode 100644 index 00000000..80da343c --- /dev/null +++ b/backend/src/main/resources/db/migration/V14__normalize_phone_numbers.sql @@ -0,0 +1,34 @@ +-- Normalize existing phone numbers to (XXX) XXX-XXXX format + +-- Update users table +UPDATE users +SET phone = '(' || SUBSTRING(clean_digits, 1, 3) || ') ' || SUBSTRING(clean_digits, 4, 3) || '-' || SUBSTRING(clean_digits, 7, 4) +FROM ( + SELECT id, + RIGHT(regexp_replace(phone, '\D', '', 'g'), 10) as clean_digits + FROM users + WHERE regexp_replace(phone, '\D', '', 'g') ~ '\d{10,}$' +) AS sub +WHERE users.id = sub.id; + +-- Update supplier table +UPDATE supplier +SET supPhone = '(' || SUBSTRING(clean_digits, 1, 3) || ') ' || SUBSTRING(clean_digits, 4, 3) || '-' || SUBSTRING(clean_digits, 7, 4) +FROM ( + SELECT supId, + RIGHT(regexp_replace(supPhone, '\D', '', 'g'), 10) as clean_digits + FROM supplier + WHERE regexp_replace(supPhone, '\D', '', 'g') ~ '\d{10,}$' +) AS sub +WHERE supplier.supId = sub.supId; + +-- Update storeLocation table +UPDATE storeLocation +SET phone = '(' || SUBSTRING(clean_digits, 1, 3) || ') ' || SUBSTRING(clean_digits, 4, 3) || '-' || SUBSTRING(clean_digits, 7, 4) +FROM ( + SELECT storeId, + RIGHT(regexp_replace(phone, '\D', '', 'g'), 10) as clean_digits + FROM storeLocation + WHERE regexp_replace(phone, '\D', '', 'g') ~ '\d{10,}$' +) AS sub +WHERE storeLocation.storeId = sub.storeId; From 054094a61e464a50416c1d4a44c528778fa2c65e Mon Sep 17 00:00:00 2001 From: Harkamal Randhawa Date: Wed, 1 Apr 2026 18:10:20 -0600 Subject: [PATCH 2/2] Add desktop icons --- .../petshopdesktop/main-layout-view.fxml | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/desktop/src/main/resources/org/example/petshopdesktop/main-layout-view.fxml b/desktop/src/main/resources/org/example/petshopdesktop/main-layout-view.fxml index 4e1cee6f..bbd78692 100644 --- a/desktop/src/main/resources/org/example/petshopdesktop/main-layout-view.fxml +++ b/desktop/src/main/resources/org/example/petshopdesktop/main-layout-view.fxml @@ -91,7 +91,7 @@ - - - - - - - - - - - -