diff --git a/backend/src/main/java/com/petshop/backend/controller/AppointmentController.java b/backend/src/main/java/com/petshop/backend/controller/AppointmentController.java index 5e64afd9..4c9d402b 100644 --- a/backend/src/main/java/com/petshop/backend/controller/AppointmentController.java +++ b/backend/src/main/java/com/petshop/backend/controller/AppointmentController.java @@ -50,7 +50,7 @@ public class AppointmentController { .orElse(null); Long effectiveCustomerId = customerId; - if (role != null && role.equals("CUSTOMER")) { + if (role != null && (role.equals("CUSTOMER") || role.equals("ADMIN"))) { User user = AuthenticationHelper.getAuthenticatedUser(userRepository); effectiveCustomerId = user.getId(); } @@ -88,7 +88,7 @@ public class AppointmentController { .map(authority -> authority.getAuthority().replace("ROLE_", "")) .orElse(null); - if (role != null && role.equals("CUSTOMER")) { + if (role != null && (role.equals("CUSTOMER") || role.equals("ADMIN"))) { User user = AuthenticationHelper.getAuthenticatedUser(userRepository); if (!request.getCustomerId().equals(user.getId())) { throw new org.springframework.security.access.AccessDeniedException("You can only create appointments for yourself"); diff --git a/web/app/appointments/page.js b/web/app/appointments/page.js index cd3746a6..ce90e858 100644 --- a/web/app/appointments/page.js +++ b/web/app/appointments/page.js @@ -224,7 +224,7 @@ function AppointmentsPage() { const [appointments, setAppointments] = useState([]); const [loadingAppointments, setLoadingAppointments] = useState(false); - const canBookAppointments = user?.role === "CUSTOMER"; +const canBookAppointments = user?.role === "CUSTOMER" || user?.role === "ADMIN"; useEffect(() => { if (!authLoading && !user) { @@ -410,12 +410,6 @@ function AppointmentsPage() { return; } - if (!user?.customerId) { - setError("Customer account not found. Please contact support."); - - return; - } - if (selectedPetIds.length === 0) { setError(isAdoptionService ? "Please select a pet to adopt." : "Please select at least one pet."); @@ -426,7 +420,7 @@ function AppointmentsPage() { try { const body = { - customerId: user.customerId, + customerId: user.customerId || user.id, storeId: Number(storeId), serviceId: Number(serviceId), employeeId: employeeId ? Number(employeeId) : undefined, @@ -435,12 +429,8 @@ function AppointmentsPage() { appointmentStatus: "Booked", }; - if (isCustomerPetService) { - body.customerPetIds = selectedPetIds; - } - - else { - body.petIds = selectedPetIds; + if (selectedPetIds.length > 0) { + body.petId = selectedPetIds[0]; } const res = await fetch(`${API_BASE}/api/v1/appointments`, { diff --git a/web/app/profile/page.js b/web/app/profile/page.js index ff79521e..cf2f0d2d 100644 --- a/web/app/profile/page.js +++ b/web/app/profile/page.js @@ -108,7 +108,7 @@ export default function ProfilePage() { }, [clearPetImageObjectUrls]); useEffect(() => { - if (user?.role === "CUSTOMER") { +if (user?.role === "CUSTOMER" || user?.role === "ADMIN") { loadPets(); } }, [user, loadPets]); @@ -419,7 +419,7 @@ export default function ProfilePage() { - {user.role === "CUSTOMER" && ( +{(user.role === "CUSTOMER" || user.role === "ADMIN") && (