From da115fd824403e2389ebd74be6217055f2c10b42 Mon Sep 17 00:00:00 2001 From: augmentedpotato Date: Wed, 15 Apr 2026 01:34:49 -0600 Subject: [PATCH] loyalty points --- .../petshop/backend/controller/AuthController.java | 3 ++- .../petshop/backend/dto/auth/UserInfoResponse.java | 12 +++++++++++- web/app/cart/page.js | 9 ++++++++- web/app/globals.css | 10 ++++++++++ web/app/profile/page.js | 1 + 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/com/petshop/backend/controller/AuthController.java b/backend/src/main/java/com/petshop/backend/controller/AuthController.java index 4e9939c8..693d0171 100644 --- a/backend/src/main/java/com/petshop/backend/controller/AuthController.java +++ b/backend/src/main/java/com/petshop/backend/controller/AuthController.java @@ -267,7 +267,8 @@ public class AuthController { user.getRole().name(), customerId, primaryStore != null ? primaryStore.getStoreId() : null, - primaryStore != null ? primaryStore.getStoreName() : null + primaryStore != null ? primaryStore.getStoreName() : null, + user.getLoyaltyPoints() ); } diff --git a/backend/src/main/java/com/petshop/backend/dto/auth/UserInfoResponse.java b/backend/src/main/java/com/petshop/backend/dto/auth/UserInfoResponse.java index e88c272d..74dbc039 100644 --- a/backend/src/main/java/com/petshop/backend/dto/auth/UserInfoResponse.java +++ b/backend/src/main/java/com/petshop/backend/dto/auth/UserInfoResponse.java @@ -15,11 +15,12 @@ public class UserInfoResponse { private Long customerId; private Long storeId; private String storeName; + private Integer loyaltyPoints; public UserInfoResponse() { } - public UserInfoResponse(Long id, String username, String firstName, String lastName, String email, String fullName, String phone, String avatarUrl, String role, Long customerId, Long storeId, String storeName) { + public UserInfoResponse(Long id, String username, String firstName, String lastName, String email, String fullName, String phone, String avatarUrl, String role, Long customerId, Long storeId, String storeName, Integer loyaltyPoints) { this.id = id; this.username = username; this.firstName = firstName; @@ -32,6 +33,7 @@ public class UserInfoResponse { this.customerId = customerId; this.storeId = storeId; this.storeName = storeName; + this.loyaltyPoints = loyaltyPoints; } public Long getId() { @@ -131,6 +133,14 @@ public class UserInfoResponse { this.storeName = storeName; } + public Integer getLoyaltyPoints() { + return loyaltyPoints; + } + + public void setLoyaltyPoints(Integer loyaltyPoints) { + this.loyaltyPoints = loyaltyPoints; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/web/app/cart/page.js b/web/app/cart/page.js index f2eb897b..f13d2901 100644 --- a/web/app/cart/page.js +++ b/web/app/cart/page.js @@ -74,7 +74,7 @@ function PaymentForm({ clientSecret, totalAmount, onSuccess, onCancel }) { } export default function CartPage() { - const { user, loading: authLoading } = useAuth(); + const { user, loading: authLoading, refreshUser } = useAuth(); const { cart, cartLoading, @@ -373,6 +373,12 @@ export default function CartPage() { )} + {user?.role === "CUSTOMER" && ( +
+ ⭐ Earn {Math.floor(parseFloat(cart.totalAmount ?? 0))} loyalty point{Math.floor(parseFloat(cart.totalAmount ?? 0)) !== 1 ? "s" : ""} with this purchase +
+ )} +
{cart.couponCode && (
@@ -444,6 +450,7 @@ export default function CartPage() { onSuccess={() => { setClientSecret(null); setConfirmed(true); + refreshUser().catch(() => {}); }} onCancel={async () => { await cancelCheckout().catch(() => {}); diff --git a/web/app/globals.css b/web/app/globals.css index 922867f4..530c7463 100644 --- a/web/app/globals.css +++ b/web/app/globals.css @@ -2413,6 +2413,16 @@ body { text-align: center; } +.cart-points-estimate { + background: #fffbeb; + border: 1px solid #fde68a; + color: #92400e; + border-radius: 8px; + padding: 0.5rem 0.85rem; + font-size: 0.85rem; + text-align: center; +} + .cart-coupon-section { display: flex; flex-direction: column; diff --git a/web/app/profile/page.js b/web/app/profile/page.js index ddb23d62..a96d9f59 100644 --- a/web/app/profile/page.js +++ b/web/app/profile/page.js @@ -396,6 +396,7 @@ export default function ProfilePage() { {label: "Email", value: user.email}, {label: "Phone", value: user.phone || "N/A"}, ...(user.storeName ? [{ label: "Store", value: user.storeName }] : []), + ...(user.role === "CUSTOMER" ? [{ label: "Loyalty Points", value: user.loyaltyPoints ?? 0 }] : []), ]; return (