diff --git a/android/app/src/main/java/com/example/petstoremobile/api/AppointmentApi.java b/android/app/src/main/java/com/example/petstoremobile/api/AppointmentApi.java index 483c66db..d811b2e0 100644 --- a/android/app/src/main/java/com/example/petstoremobile/api/AppointmentApi.java +++ b/android/app/src/main/java/com/example/petstoremobile/api/AppointmentApi.java @@ -21,7 +21,8 @@ public interface AppointmentApi { @Query("q") String query, @Query("status") String status, @Query("storeId") Long storeId, - @Query("date") String date); + @Query("date") String date, + @Query("employeeId") Long employeeId); @GET("api/v1/appointments/{id}") Call getAppointmentById(@Path("id") Long id); diff --git a/android/app/src/main/java/com/example/petstoremobile/fragments/listfragments/AppointmentFragment.java b/android/app/src/main/java/com/example/petstoremobile/fragments/listfragments/AppointmentFragment.java index fab6a0b5..3724850b 100644 --- a/android/app/src/main/java/com/example/petstoremobile/fragments/listfragments/AppointmentFragment.java +++ b/android/app/src/main/java/com/example/petstoremobile/fragments/listfragments/AppointmentFragment.java @@ -30,6 +30,7 @@ import com.example.petstoremobile.utils.Resource; import com.example.petstoremobile.utils.SpinnerUtils; import com.example.petstoremobile.viewmodels.AppointmentViewModel; import com.example.petstoremobile.utils.EventDecorator; +import com.example.petstoremobile.viewmodels.AuthViewModel; import com.example.petstoremobile.viewmodels.StoreViewModel; import com.prolificinteractive.materialcalendarview.CalendarDay; import com.prolificinteractive.materialcalendarview.CalendarMode; @@ -55,9 +56,11 @@ public class AppointmentFragment extends Fragment implements AppointmentAdapter. private AppointmentAdapter adapter; private AppointmentViewModel appointmentViewModel; private StoreViewModel storeViewModel; + private AuthViewModel authViewModel; private CalendarDay selectedCalendarDay; private boolean isMonthMode = false; + private Long currentUserId = null; private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); /** @@ -68,6 +71,7 @@ public class AppointmentFragment extends Fragment implements AppointmentAdapter. super.onCreate(savedInstanceState); appointmentViewModel = new ViewModelProvider(this).get(AppointmentViewModel.class); storeViewModel = new ViewModelProvider(this).get(StoreViewModel.class); + authViewModel = new ViewModelProvider(this).get(AuthViewModel.class); } /** @@ -85,6 +89,7 @@ public class AppointmentFragment extends Fragment implements AppointmentAdapter. setupSwipeRefresh(); setupCalendar(); setupFilterToggle(); + setupMyAppointmentFilter(); binding.fabAddAppointment.setOnClickListener(v -> openAppointmentDetails(-1)); @@ -100,6 +105,8 @@ public class AppointmentFragment extends Fragment implements AppointmentAdapter. binding.btnToggleCalendarMode.setOnClickListener(v -> toggleCalendarMode()); + loadCurrentUserInfo(); + return binding.getRoot(); } @@ -126,6 +133,26 @@ public class AppointmentFragment extends Fragment implements AppointmentAdapter. .commit(); } + /** + * Sets up the "My Appointments" filter button. + */ + private void setupMyAppointmentFilter() { + binding.btnMyAppointments.setOnClickListener(v -> { + loadAppointmentData(); + }); + } + + /** + * Fetches current user info to get the employeeId. + */ + private void loadCurrentUserInfo() { + authViewModel.getMe().observe(getViewLifecycleOwner(), resource -> { + if (resource.status == Resource.Status.SUCCESS && resource.data != null) { + currentUserId = resource.data.getId(); + } + }); + } + /** * Sets up the filter toggle button to show/hide the filter layout. */ @@ -142,6 +169,7 @@ public class AppointmentFragment extends Fragment implements AppointmentAdapter. binding.etSearchAppointment.setText(""); binding.spinnerStatus.setSelection(0); binding.spinnerStore.setSelection(0); + binding.btnMyAppointments.setChecked(false); selectedCalendarDay = null; binding.calendarView.clearSelection(); } @@ -293,10 +321,15 @@ public class AppointmentFragment extends Fragment implements AppointmentAdapter. selectedCalendarDay.getYear(), selectedCalendarDay.getMonth(), selectedCalendarDay.getDay()); } + Long employeeId = null; + if (binding.btnMyAppointments.isChecked()) { + employeeId = currentUserId; + } + if (status.equals("All Statuses")) status = null; else status = status.toUpperCase(); - appointmentViewModel.getAllAppointments(0, 500, query, status, storeId, selectedDateString).observe(getViewLifecycleOwner(), resource -> { + appointmentViewModel.getAllAppointments(0, 500, query, status, storeId, selectedDateString, employeeId).observe(getViewLifecycleOwner(), resource -> { if (resource == null) return; // Check the status to see if the resource is loaded and display the data diff --git a/android/app/src/main/java/com/example/petstoremobile/repositories/AppointmentRepository.java b/android/app/src/main/java/com/example/petstoremobile/repositories/AppointmentRepository.java index 21c4fdc9..1c85e91a 100644 --- a/android/app/src/main/java/com/example/petstoremobile/repositories/AppointmentRepository.java +++ b/android/app/src/main/java/com/example/petstoremobile/repositories/AppointmentRepository.java @@ -23,8 +23,8 @@ public class AppointmentRepository extends BaseRepository { /** * Retrieves a paginated list of all appointments from the API with filtering. */ - public LiveData>> getAllAppointments(int page, int size, String query, String status, Long storeId, String date) { - return executeCall(appointmentApi.getAllAppointments(page, size, query, status, storeId, date)); + public LiveData>> getAllAppointments(int page, int size, String query, String status, Long storeId, String date, Long employeeId) { + return executeCall(appointmentApi.getAllAppointments(page, size, query, status, storeId, date, employeeId)); } /** diff --git a/android/app/src/main/java/com/example/petstoremobile/viewmodels/AppointmentViewModel.java b/android/app/src/main/java/com/example/petstoremobile/viewmodels/AppointmentViewModel.java index c97dc97c..913d7ab2 100644 --- a/android/app/src/main/java/com/example/petstoremobile/viewmodels/AppointmentViewModel.java +++ b/android/app/src/main/java/com/example/petstoremobile/viewmodels/AppointmentViewModel.java @@ -24,8 +24,8 @@ public class AppointmentViewModel extends ViewModel { /** * Fetches a paginated list of all appointments with optional filters. */ - public LiveData>> getAllAppointments(int page, int size, String query, String status, Long storeId, String date) { - return repository.getAllAppointments(page, size, query, status, storeId, date); + public LiveData>> getAllAppointments(int page, int size, String query, String status, Long storeId, String date, Long employeeId) { + return repository.getAllAppointments(page, size, query, status, storeId, date, employeeId); } /** diff --git a/android/app/src/main/res/layout/fragment_appointment.xml b/android/app/src/main/res/layout/fragment_appointment.xml index f8a98ec2..8afc956c 100644 --- a/android/app/src/main/res/layout/fragment_appointment.xml +++ b/android/app/src/main/res/layout/fragment_appointment.xml @@ -130,6 +130,18 @@ + +