added my appointments button for logged in user on andriod

This commit is contained in:
Alex
2026-04-07 06:48:36 -06:00
parent 094c2d4a48
commit 0a55014f21
5 changed files with 52 additions and 6 deletions

View File

@@ -21,7 +21,8 @@ public interface AppointmentApi {
@Query("q") String query, @Query("q") String query,
@Query("status") String status, @Query("status") String status,
@Query("storeId") Long storeId, @Query("storeId") Long storeId,
@Query("date") String date); @Query("date") String date,
@Query("employeeId") Long employeeId);
@GET("api/v1/appointments/{id}") @GET("api/v1/appointments/{id}")
Call<AppointmentDTO> getAppointmentById(@Path("id") Long id); Call<AppointmentDTO> getAppointmentById(@Path("id") Long id);

View File

@@ -30,6 +30,7 @@ import com.example.petstoremobile.utils.Resource;
import com.example.petstoremobile.utils.SpinnerUtils; import com.example.petstoremobile.utils.SpinnerUtils;
import com.example.petstoremobile.viewmodels.AppointmentViewModel; import com.example.petstoremobile.viewmodels.AppointmentViewModel;
import com.example.petstoremobile.utils.EventDecorator; import com.example.petstoremobile.utils.EventDecorator;
import com.example.petstoremobile.viewmodels.AuthViewModel;
import com.example.petstoremobile.viewmodels.StoreViewModel; import com.example.petstoremobile.viewmodels.StoreViewModel;
import com.prolificinteractive.materialcalendarview.CalendarDay; import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.CalendarMode; import com.prolificinteractive.materialcalendarview.CalendarMode;
@@ -55,9 +56,11 @@ public class AppointmentFragment extends Fragment implements AppointmentAdapter.
private AppointmentAdapter adapter; private AppointmentAdapter adapter;
private AppointmentViewModel appointmentViewModel; private AppointmentViewModel appointmentViewModel;
private StoreViewModel storeViewModel; private StoreViewModel storeViewModel;
private AuthViewModel authViewModel;
private CalendarDay selectedCalendarDay; private CalendarDay selectedCalendarDay;
private boolean isMonthMode = false; private boolean isMonthMode = false;
private Long currentUserId = null;
private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); 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); super.onCreate(savedInstanceState);
appointmentViewModel = new ViewModelProvider(this).get(AppointmentViewModel.class); appointmentViewModel = new ViewModelProvider(this).get(AppointmentViewModel.class);
storeViewModel = new ViewModelProvider(this).get(StoreViewModel.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(); setupSwipeRefresh();
setupCalendar(); setupCalendar();
setupFilterToggle(); setupFilterToggle();
setupMyAppointmentFilter();
binding.fabAddAppointment.setOnClickListener(v -> openAppointmentDetails(-1)); binding.fabAddAppointment.setOnClickListener(v -> openAppointmentDetails(-1));
@@ -100,6 +105,8 @@ public class AppointmentFragment extends Fragment implements AppointmentAdapter.
binding.btnToggleCalendarMode.setOnClickListener(v -> toggleCalendarMode()); binding.btnToggleCalendarMode.setOnClickListener(v -> toggleCalendarMode());
loadCurrentUserInfo();
return binding.getRoot(); return binding.getRoot();
} }
@@ -126,6 +133,26 @@ public class AppointmentFragment extends Fragment implements AppointmentAdapter.
.commit(); .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. * 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.etSearchAppointment.setText("");
binding.spinnerStatus.setSelection(0); binding.spinnerStatus.setSelection(0);
binding.spinnerStore.setSelection(0); binding.spinnerStore.setSelection(0);
binding.btnMyAppointments.setChecked(false);
selectedCalendarDay = null; selectedCalendarDay = null;
binding.calendarView.clearSelection(); binding.calendarView.clearSelection();
} }
@@ -293,10 +321,15 @@ public class AppointmentFragment extends Fragment implements AppointmentAdapter.
selectedCalendarDay.getYear(), selectedCalendarDay.getMonth(), selectedCalendarDay.getDay()); selectedCalendarDay.getYear(), selectedCalendarDay.getMonth(), selectedCalendarDay.getDay());
} }
Long employeeId = null;
if (binding.btnMyAppointments.isChecked()) {
employeeId = currentUserId;
}
if (status.equals("All Statuses")) status = null; if (status.equals("All Statuses")) status = null;
else status = status.toUpperCase(); 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; if (resource == null) return;
// Check the status to see if the resource is loaded and display the data // Check the status to see if the resource is loaded and display the data

View File

@@ -23,8 +23,8 @@ public class AppointmentRepository extends BaseRepository {
/** /**
* Retrieves a paginated list of all appointments from the API with filtering. * Retrieves a paginated list of all appointments from the API with filtering.
*/ */
public LiveData<Resource<PageResponse<AppointmentDTO>>> getAllAppointments(int page, int size, String query, String status, Long storeId, String date) { public LiveData<Resource<PageResponse<AppointmentDTO>>> 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)); return executeCall(appointmentApi.getAllAppointments(page, size, query, status, storeId, date, employeeId));
} }
/** /**

View File

@@ -24,8 +24,8 @@ public class AppointmentViewModel extends ViewModel {
/** /**
* Fetches a paginated list of all appointments with optional filters. * Fetches a paginated list of all appointments with optional filters.
*/ */
public LiveData<Resource<PageResponse<AppointmentDTO>>> getAllAppointments(int page, int size, String query, String status, Long storeId, String date) { public LiveData<Resource<PageResponse<AppointmentDTO>>> getAllAppointments(int page, int size, String query, String status, Long storeId, String date, Long employeeId) {
return repository.getAllAppointments(page, size, query, status, storeId, date); return repository.getAllAppointments(page, size, query, status, storeId, date, employeeId);
} }
/** /**

View File

@@ -130,6 +130,18 @@
</LinearLayout> </LinearLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/btnMyAppointments"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="My Appointments"
android:textColor="@color/white"
app:strokeColor="@color/white"
app:rippleColor="#33FFFFFF"
android:checkable="true"/>
</LinearLayout> </LinearLayout>
<com.prolificinteractive.materialcalendarview.MaterialCalendarView <com.prolificinteractive.materialcalendarview.MaterialCalendarView