update dropdowns to use backend dropdown endpoints part 1

This commit is contained in:
Alex
2026-04-08 17:34:33 -06:00
parent 8d5d6f3872
commit 1e37f25a7a
14 changed files with 163 additions and 87 deletions

View File

@@ -1,6 +1,7 @@
package com.example.petstoremobile.api; package com.example.petstoremobile.api;
import com.example.petstoremobile.dtos.CustomerDTO; import com.example.petstoremobile.dtos.CustomerDTO;
import com.example.petstoremobile.dtos.DropdownDTO;
import com.example.petstoremobile.dtos.PageResponse; import com.example.petstoremobile.dtos.PageResponse;
import java.util.List; import java.util.List;
@@ -18,4 +19,7 @@ public interface CustomerApi {
@GET("api/v1/customers/{customerId}") @GET("api/v1/customers/{customerId}")
Call<CustomerDTO> getCustomerById(@Path("customerId") Long customerId); Call<CustomerDTO> getCustomerById(@Path("customerId") Long customerId);
@GET("api/v1/dropdowns/customers")
Call<List<DropdownDTO>> getCustomerDropdowns();
} }

View File

@@ -1,9 +1,12 @@
package com.example.petstoremobile.api; package com.example.petstoremobile.api;
import com.example.petstoremobile.dtos.BulkDeleteRequest; import com.example.petstoremobile.dtos.BulkDeleteRequest;
import com.example.petstoremobile.dtos.DropdownDTO;
import com.example.petstoremobile.dtos.PageResponse; import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.dtos.PetDTO; import com.example.petstoremobile.dtos.PetDTO;
import java.util.List;
import okhttp3.MultipartBody; import okhttp3.MultipartBody;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.http.Body; import retrofit2.http.Body;
@@ -35,6 +38,12 @@ public interface PetApi {
@Query("sort") String sort @Query("sort") String sort
); );
@GET("api/v1/dropdowns/customers/{customerId}/pets")
Call<List<DropdownDTO>> getCustomerPets(@Path("customerId") Long customerId);
@GET("api/v1/dropdowns/adoption-pets")
Call<List<DropdownDTO>> getAdoptionPets();
// Get pet by id // Get pet by id
@GET("api/v1/pets/{id}") @GET("api/v1/pets/{id}")
Call<PetDTO> getPetById(@Path("id") Long id); Call<PetDTO> getPetById(@Path("id") Long id);

View File

@@ -18,6 +18,9 @@ public interface StoreApi {
@Query("page") int page, @Query("page") int page,
@Query("size") int size); @Query("size") int size);
@GET("api/v1/dropdowns/stores")
Call<List<DropdownDTO>> getStoreDropdowns();
@GET("api/v1/dropdowns/stores/{storeId}/employees") @GET("api/v1/dropdowns/stores/{storeId}/employees")
Call<List<DropdownDTO>> getStoreEmployees(@Path("storeId") Long storeId); Call<List<DropdownDTO>> getStoreEmployees(@Path("storeId") Long storeId);
} }

View File

@@ -41,9 +41,9 @@ public class AdoptionDetailFragment extends Fragment {
private long preselectedStoreId = -1; private long preselectedStoreId = -1;
private long preselectedEmployeeId = -1; private long preselectedEmployeeId = -1;
private List<PetDTO> petList = new ArrayList<>(); private List<DropdownDTO> petList = new ArrayList<>();
private List<CustomerDTO> customerList = new ArrayList<>(); private List<DropdownDTO> customerList = new ArrayList<>();
private List<StoreDTO> storeList = new ArrayList<>(); private List<DropdownDTO> storeList = new ArrayList<>();
private List<UserDTO> employeeList = new ArrayList<>(); private List<UserDTO> employeeList = new ArrayList<>();
private final String[] STATUSES = {"Pending", "Completed", "Cancelled"}; private final String[] STATUSES = {"Pending", "Completed", "Cancelled"};
@@ -126,9 +126,9 @@ public class AdoptionDetailFragment extends Fragment {
* Loads the list of pets from the API. * Loads the list of pets from the API.
*/ */
private void loadPets() { private void loadPets() {
petViewModel.getAllPets(0, 200, null, null, null, null, null, "petName").observe(getViewLifecycleOwner(), resource -> { petViewModel.getAdoptionPets().observe(getViewLifecycleOwner(), resource -> {
if (resource.status == Resource.Status.SUCCESS && resource.data != null) { if (resource.status == Resource.Status.SUCCESS && resource.data != null) {
petList = resource.data.getContent(); petList = resource.data;
refreshPetSpinner(); refreshPetSpinner();
} }
}); });
@@ -139,17 +139,17 @@ public class AdoptionDetailFragment extends Fragment {
*/ */
private void refreshPetSpinner() { private void refreshPetSpinner() {
SpinnerUtils.populateSpinner(requireContext(), binding.spinnerAdoptionPet, petList, SpinnerUtils.populateSpinner(requireContext(), binding.spinnerAdoptionPet, petList,
PetDTO::getPetName, "-- Select Pet --", DropdownDTO::getLabel, "-- Select Pet --",
preselectedPetId, PetDTO::getPetId); preselectedPetId, DropdownDTO::getId);
} }
/** /**
* Loads the list of customers from the API. * Loads the list of customers from the API.
*/ */
private void loadCustomers() { private void loadCustomers() {
customerViewModel.getAllCustomers(0, 200).observe(getViewLifecycleOwner(), resource -> { customerViewModel.getCustomerDropdowns().observe(getViewLifecycleOwner(), resource -> {
if (resource.status == Resource.Status.SUCCESS && resource.data != null) { if (resource.status == Resource.Status.SUCCESS && resource.data != null) {
customerList = resource.data.getContent(); customerList = resource.data;
refreshCustomerSpinner(); refreshCustomerSpinner();
} }
}); });
@@ -160,18 +160,18 @@ public class AdoptionDetailFragment extends Fragment {
*/ */
private void refreshCustomerSpinner() { private void refreshCustomerSpinner() {
SpinnerUtils.populateSpinner(requireContext(), binding.spinnerAdoptionCustomer, customerList, SpinnerUtils.populateSpinner(requireContext(), binding.spinnerAdoptionCustomer, customerList,
item -> item.getFirstName() + " " + item.getLastName(), DropdownDTO::getLabel,
"-- Select Customer --", "-- Select Customer --",
preselectedCustomerId, CustomerDTO::getCustomerId); preselectedCustomerId, DropdownDTO::getId);
} }
/** /**
* Loads the list of stores from the API. * Loads the list of stores from the API.
*/ */
private void loadStores() { private void loadStores() {
storeViewModel.getAllStores(0, 200).observe(getViewLifecycleOwner(), resource -> { storeViewModel.getStoreDropdowns().observe(getViewLifecycleOwner(), resource -> {
if (resource.status == Resource.Status.SUCCESS && resource.data != null) { if (resource.status == Resource.Status.SUCCESS && resource.data != null) {
storeList = resource.data.getContent(); storeList = resource.data;
refreshStoreSpinner(); refreshStoreSpinner();
} }
}); });
@@ -182,8 +182,8 @@ public class AdoptionDetailFragment extends Fragment {
*/ */
private void refreshStoreSpinner() { private void refreshStoreSpinner() {
SpinnerUtils.populateSpinner(requireContext(), binding.spinnerAdoptionStore, storeList, SpinnerUtils.populateSpinner(requireContext(), binding.spinnerAdoptionStore, storeList,
StoreDTO::getStoreName, "-- Select Store --", DropdownDTO::getLabel, "-- Select Store --",
preselectedStoreId, StoreDTO::getStoreId); preselectedStoreId, DropdownDTO::getId);
} }
/** /**
@@ -283,9 +283,9 @@ public class AdoptionDetailFragment extends Fragment {
} }
} }
CustomerDTO customer = customerList.get(binding.spinnerAdoptionCustomer.getSelectedItemPosition() - 1); DropdownDTO customer = customerList.get(binding.spinnerAdoptionCustomer.getSelectedItemPosition() - 1);
PetDTO pet = petList.get(binding.spinnerAdoptionPet.getSelectedItemPosition() - 1); DropdownDTO pet = petList.get(binding.spinnerAdoptionPet.getSelectedItemPosition() - 1);
StoreDTO store = storeList.get(binding.spinnerAdoptionStore.getSelectedItemPosition() - 1); DropdownDTO store = storeList.get(binding.spinnerAdoptionStore.getSelectedItemPosition() - 1);
Long employeeId = null; Long employeeId = null;
if (binding.spinnerAdoptionEmployee.getSelectedItemPosition() > 0) { if (binding.spinnerAdoptionEmployee.getSelectedItemPosition() > 0) {
@@ -295,10 +295,10 @@ public class AdoptionDetailFragment extends Fragment {
String status = STATUSES[binding.spinnerAdoptionStatus.getSelectedItemPosition()]; String status = STATUSES[binding.spinnerAdoptionStatus.getSelectedItemPosition()];
AdoptionDTO dto = new AdoptionDTO( AdoptionDTO dto = new AdoptionDTO(
pet.getPetId(), pet.getId(),
customer.getCustomerId(), customer.getId(),
employeeId, employeeId,
store.getStoreId(), store.getId(),
date, date,
status, status,
fee fee

View File

@@ -43,10 +43,10 @@ public class AppointmentDetailFragment extends Fragment {
private long preselectedStoreId = -1; private long preselectedStoreId = -1;
private long preselectedStaffId = -1; private long preselectedStaffId = -1;
private List<PetDTO> petList = new ArrayList<>(); private List<DropdownDTO> petList = new ArrayList<>();
private List<ServiceDTO> serviceList = new ArrayList<>(); private List<ServiceDTO> serviceList = new ArrayList<>();
private List<CustomerDTO> customerList = new ArrayList<>(); private List<DropdownDTO> customerList = new ArrayList<>();
private List<StoreDTO> storeList = new ArrayList<>(); private List<DropdownDTO> storeList = new ArrayList<>();
private List<DropdownDTO> staffList = new ArrayList<>(); private List<DropdownDTO> staffList = new ArrayList<>();
private final Integer[] HOURS = {9,10,11,12,13,14,15,16,17}; private final Integer[] HOURS = {9,10,11,12,13,14,15,16,17};
@@ -113,8 +113,8 @@ public class AppointmentDetailFragment extends Fragment {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position > 0 && position <= customerList.size()) { if (position > 0 && position <= customerList.size()) {
CustomerDTO selectedCustomer = customerList.get(position - 1); DropdownDTO selectedCustomer = customerList.get(position - 1);
loadPets(selectedCustomer.getCustomerId()); loadPets(selectedCustomer.getId());
} else { } else {
petList.clear(); petList.clear();
refreshPetSpinner(); refreshPetSpinner();
@@ -130,8 +130,8 @@ public class AppointmentDetailFragment extends Fragment {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position > 0 && position <= storeList.size()) { if (position > 0 && position <= storeList.size()) {
StoreDTO selectedStore = storeList.get(position - 1); DropdownDTO selectedStore = storeList.get(position - 1);
loadStaff(selectedStore.getStoreId()); loadStaff(selectedStore.getId());
} else { } else {
staffList.clear(); staffList.clear();
refreshStaffSpinner(); refreshStaffSpinner();
@@ -172,9 +172,9 @@ public class AppointmentDetailFragment extends Fragment {
* Loads the list of pets from the ViewModel, filtered by customerId. * Loads the list of pets from the ViewModel, filtered by customerId.
*/ */
private void loadPets(Long customerId) { private void loadPets(Long customerId) {
petViewModel.getAllPets(0, 200, null, null, null, null, customerId, "petName").observe(getViewLifecycleOwner(), resource -> { petViewModel.getCustomerPets(customerId).observe(getViewLifecycleOwner(), resource -> {
if (resource.status == Resource.Status.SUCCESS && resource.data != null) { if (resource.status == Resource.Status.SUCCESS && resource.data != null) {
petList = resource.data.getContent(); petList = resource.data;
refreshPetSpinner(); refreshPetSpinner();
} }
}); });
@@ -185,8 +185,8 @@ public class AppointmentDetailFragment extends Fragment {
*/ */
private void refreshPetSpinner() { private void refreshPetSpinner() {
SpinnerUtils.populateSpinner(requireContext(), binding.spinnerPet, petList, SpinnerUtils.populateSpinner(requireContext(), binding.spinnerPet, petList,
PetDTO::getPetName, "-- Select Pet --", DropdownDTO::getLabel, "-- Select Pet --",
preselectedPetId, PetDTO::getPetId); preselectedPetId, DropdownDTO::getId);
} }
/** /**
@@ -214,9 +214,9 @@ public class AppointmentDetailFragment extends Fragment {
* Loads the list of customers from the API. * Loads the list of customers from the API.
*/ */
private void loadCustomers() { private void loadCustomers() {
customerViewModel.getAllCustomers(0, 200).observe(getViewLifecycleOwner(), resource -> { customerViewModel.getCustomerDropdowns().observe(getViewLifecycleOwner(), resource -> {
if (resource.status == Resource.Status.SUCCESS && resource.data != null) { if (resource.status == Resource.Status.SUCCESS && resource.data != null) {
customerList = resource.data.getContent(); customerList = resource.data;
refreshCustomerSpinner(); refreshCustomerSpinner();
} }
}); });
@@ -227,18 +227,18 @@ public class AppointmentDetailFragment extends Fragment {
*/ */
private void refreshCustomerSpinner() { private void refreshCustomerSpinner() {
SpinnerUtils.populateSpinner(requireContext(), binding.spinnerCustomer, customerList, SpinnerUtils.populateSpinner(requireContext(), binding.spinnerCustomer, customerList,
item -> item.getFirstName() + " " + item.getLastName(), DropdownDTO::getLabel,
"-- Select Customer --", "-- Select Customer --",
preselectedCustomerId, CustomerDTO::getCustomerId); preselectedCustomerId, DropdownDTO::getId);
} }
/** /**
* Loads the list of stores from the API. * Loads the list of stores from the API.
*/ */
private void loadStores() { private void loadStores() {
storeViewModel.getAllStores(0, 50).observe(getViewLifecycleOwner(), resource -> { storeViewModel.getStoreDropdowns().observe(getViewLifecycleOwner(), resource -> {
if (resource.status == Resource.Status.SUCCESS && resource.data != null) { if (resource.status == Resource.Status.SUCCESS && resource.data != null) {
storeList = resource.data.getContent(); storeList = resource.data;
refreshStoreSpinner(); refreshStoreSpinner();
} }
}); });
@@ -249,8 +249,8 @@ public class AppointmentDetailFragment extends Fragment {
*/ */
private void refreshStoreSpinner() { private void refreshStoreSpinner() {
SpinnerUtils.populateSpinner(requireContext(), binding.spinnerStore, storeList, SpinnerUtils.populateSpinner(requireContext(), binding.spinnerStore, storeList,
StoreDTO::getStoreName, "-- Select Store --", DropdownDTO::getLabel, "-- Select Store --",
preselectedStoreId, StoreDTO::getStoreId); preselectedStoreId, DropdownDTO::getId);
} }
/** /**
@@ -395,9 +395,9 @@ public class AppointmentDetailFragment extends Fragment {
Toast.makeText(getContext(), "Select a date", Toast.LENGTH_SHORT).show(); return; Toast.makeText(getContext(), "Select a date", Toast.LENGTH_SHORT).show(); return;
} }
CustomerDTO customer = customerList.get(binding.spinnerCustomer.getSelectedItemPosition() - 1); DropdownDTO customer = customerList.get(binding.spinnerCustomer.getSelectedItemPosition() - 1);
StoreDTO store = storeList.get(binding.spinnerStore.getSelectedItemPosition() - 1); DropdownDTO store = storeList.get(binding.spinnerStore.getSelectedItemPosition() - 1);
PetDTO pet = petList.get(binding.spinnerPet.getSelectedItemPosition() - 1); DropdownDTO pet = petList.get(binding.spinnerPet.getSelectedItemPosition() - 1);
ServiceDTO service = serviceList.get(binding.spinnerService.getSelectedItemPosition() - 1); ServiceDTO service = serviceList.get(binding.spinnerService.getSelectedItemPosition() - 1);
Long employeeId = null; Long employeeId = null;
@@ -440,14 +440,14 @@ public class AppointmentDetailFragment extends Fragment {
// Build DTO with all required IDs // Build DTO with all required IDs
AppointmentDTO dto = new AppointmentDTO( AppointmentDTO dto = new AppointmentDTO(
customer.getCustomerId(), customer.getId(),
store.getStoreId(), store.getId(),
service.getServiceId(), service.getServiceId(),
employeeId, employeeId,
date, date,
time, time,
status, status,
pet.getPetId() pet.getId()
); );
androidx.lifecycle.Observer<Resource<AppointmentDTO>> observer = resource -> { androidx.lifecycle.Observer<Resource<AppointmentDTO>> observer = resource -> {

View File

@@ -14,6 +14,7 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.fragment.NavHostFragment; import androidx.navigation.fragment.NavHostFragment;
import com.example.petstoremobile.databinding.FragmentInventoryDetailBinding; import com.example.petstoremobile.databinding.FragmentInventoryDetailBinding;
import com.example.petstoremobile.dtos.DropdownDTO;
import com.example.petstoremobile.dtos.InventoryDTO; import com.example.petstoremobile.dtos.InventoryDTO;
import com.example.petstoremobile.dtos.ProductDTO; import com.example.petstoremobile.dtos.ProductDTO;
import com.example.petstoremobile.dtos.StoreDTO; import com.example.petstoremobile.dtos.StoreDTO;
@@ -46,7 +47,7 @@ public class InventoryDetailFragment extends Fragment {
private long preselectedStoreId = -1; private long preselectedStoreId = -1;
private long preselectedProductId = -1; private long preselectedProductId = -1;
private List<StoreDTO> storeList = new ArrayList<>(); private List<DropdownDTO> storeList = new ArrayList<>();
private List<ProductDTO> productList = new ArrayList<>(); private List<ProductDTO> productList = new ArrayList<>();
/** /**
@@ -103,9 +104,9 @@ public class InventoryDetailFragment extends Fragment {
* Loads the list of stores for the spinner. * Loads the list of stores for the spinner.
*/ */
private void loadStores() { private void loadStores() {
storeViewModel.getAllStores(0, 100).observe(getViewLifecycleOwner(), resource -> { storeViewModel.getStoreDropdowns().observe(getViewLifecycleOwner(), resource -> {
if (resource.status == Resource.Status.SUCCESS && resource.data != null) { if (resource.status == Resource.Status.SUCCESS && resource.data != null) {
storeList = resource.data.getContent(); storeList = resource.data;
refreshStoreSpinner(); refreshStoreSpinner();
} }
}); });
@@ -113,8 +114,8 @@ public class InventoryDetailFragment extends Fragment {
private void refreshStoreSpinner() { private void refreshStoreSpinner() {
SpinnerUtils.populateSpinner(requireContext(), binding.spinnerInventoryStore, storeList, SpinnerUtils.populateSpinner(requireContext(), binding.spinnerInventoryStore, storeList,
StoreDTO::getStoreName, "-- Select Store --", DropdownDTO::getLabel, "-- Select Store --",
preselectedStoreId, StoreDTO::getStoreId); preselectedStoreId, DropdownDTO::getId);
} }
/** /**
@@ -199,10 +200,10 @@ public class InventoryDetailFragment extends Fragment {
} }
int quantity = Integer.parseInt(binding.etQuantity.getText().toString().trim()); int quantity = Integer.parseInt(binding.etQuantity.getText().toString().trim());
StoreDTO store = storeList.get(binding.spinnerInventoryStore.getSelectedItemPosition() - 1); DropdownDTO store = storeList.get(binding.spinnerInventoryStore.getSelectedItemPosition() - 1);
ProductDTO product = productList.get(binding.spinnerInventoryProduct.getSelectedItemPosition() - 1); ProductDTO product = productList.get(binding.spinnerInventoryProduct.getSelectedItemPosition() - 1);
InventoryDTO request = new InventoryDTO(product.getProdId(), store.getStoreId(), quantity); InventoryDTO request = new InventoryDTO(product.getProdId(), store.getId(), quantity);
setButtonsEnabled(false); setButtonsEnabled(false);
if (isEditing) { if (isEditing) {

View File

@@ -18,9 +18,8 @@ import android.widget.Toast;
import com.example.petstoremobile.R; import com.example.petstoremobile.R;
import com.example.petstoremobile.databinding.FragmentPetDetailBinding; import com.example.petstoremobile.databinding.FragmentPetDetailBinding;
import com.example.petstoremobile.dtos.CustomerDTO; import com.example.petstoremobile.dtos.DropdownDTO;
import com.example.petstoremobile.dtos.PetDTO; import com.example.petstoremobile.dtos.PetDTO;
import com.example.petstoremobile.dtos.StoreDTO;
import com.example.petstoremobile.utils.ActivityLogger; import com.example.petstoremobile.utils.ActivityLogger;
import com.example.petstoremobile.utils.DialogUtils; import com.example.petstoremobile.utils.DialogUtils;
import com.example.petstoremobile.utils.InputValidator; import com.example.petstoremobile.utils.InputValidator;
@@ -49,8 +48,8 @@ public class PetDetailFragment extends Fragment {
private PetViewModel viewModel; private PetViewModel viewModel;
private CustomerViewModel customerViewModel; private CustomerViewModel customerViewModel;
private StoreViewModel storeViewModel; private StoreViewModel storeViewModel;
private List<CustomerDTO> customerList = new ArrayList<>(); private List<DropdownDTO> customerList = new ArrayList<>();
private List<StoreDTO> storeList = new ArrayList<>(); private List<DropdownDTO> storeList = new ArrayList<>();
private Long selectedCustomerId = null; private Long selectedCustomerId = null;
private Long selectedStoreId = null; private Long selectedStoreId = null;
@@ -113,14 +112,14 @@ public class PetDetailFragment extends Fragment {
Long customerId = null; Long customerId = null;
int customerPos = binding.spinnerCustomer.getSelectedItemPosition(); int customerPos = binding.spinnerCustomer.getSelectedItemPosition();
if (customerPos > 0) { // 0 means no customer for pet if (customerPos > 0) { // 0 means no customer for pet
customerId = customerList.get(customerPos - 1).getCustomerId(); customerId = customerList.get(customerPos - 1).getId();
} }
// Get selected store // Get selected store
Long storeId = null; Long storeId = null;
int storePos = binding.spinnerStore.getSelectedItemPosition(); int storePos = binding.spinnerStore.getSelectedItemPosition();
if (storePos > 0) { if (storePos > 0) {
storeId = storeList.get(storePos - 1).getStoreId(); storeId = storeList.get(storePos - 1).getId();
} }
// Validation: If status is Available, a store must be selected // Validation: If status is Available, a store must be selected
@@ -277,9 +276,9 @@ public class PetDetailFragment extends Fragment {
* Fetches the list of customers and populates the spinner. * Fetches the list of customers and populates the spinner.
*/ */
private void loadCustomers() { private void loadCustomers() {
customerViewModel.getAllCustomers(0, 1000).observe(getViewLifecycleOwner(), resource -> { customerViewModel.getCustomerDropdowns().observe(getViewLifecycleOwner(), resource -> {
if (resource != null && resource.status == Resource.Status.SUCCESS && resource.data != null) { if (resource != null && resource.status == Resource.Status.SUCCESS && resource.data != null) {
customerList = resource.data.getContent(); customerList = resource.data;
updateCustomerSpinnerSelection(); updateCustomerSpinnerSelection();
} }
}); });
@@ -289,9 +288,9 @@ public class PetDetailFragment extends Fragment {
* Fetches the list of stores and populates the spinner. * Fetches the list of stores and populates the spinner.
*/ */
private void loadStores() { private void loadStores() {
storeViewModel.getAllStores(0, 1000).observe(getViewLifecycleOwner(), resource -> { storeViewModel.getStoreDropdowns().observe(getViewLifecycleOwner(), resource -> {
if (resource != null && resource.status == Resource.Status.SUCCESS && resource.data != null) { if (resource != null && resource.status == Resource.Status.SUCCESS && resource.data != null) {
storeList = resource.data.getContent(); storeList = resource.data;
updateStoreSpinnerSelection(); updateStoreSpinnerSelection();
} }
}); });
@@ -305,10 +304,10 @@ public class PetDetailFragment extends Fragment {
requireContext(), requireContext(),
binding.spinnerCustomer, binding.spinnerCustomer,
customerList, customerList,
CustomerDTO::getFullName, DropdownDTO::getLabel,
"No Owner", "No Owner",
selectedCustomerId, selectedCustomerId,
CustomerDTO::getCustomerId DropdownDTO::getId
); );
} }
@@ -320,10 +319,10 @@ public class PetDetailFragment extends Fragment {
requireContext(), requireContext(),
binding.spinnerStore, binding.spinnerStore,
storeList, storeList,
StoreDTO::getStoreName, DropdownDTO::getLabel,
"None", "None",
selectedStoreId, selectedStoreId,
StoreDTO::getStoreId DropdownDTO::getId
); );
} }
@@ -379,4 +378,4 @@ public class PetDetailFragment extends Fragment {
((TextView) selectedView).setError(null); ((TextView) selectedView).setError(null);
} }
} }
} }

View File

@@ -31,8 +31,8 @@ public class SaleDetailFragment extends Fragment {
private boolean viewOnly = false; private boolean viewOnly = false;
private long saleId = -1; private long saleId = -1;
private List<StoreDTO> storeList = new ArrayList<>(); private List<DropdownDTO> storeList = new ArrayList<>();
private List<CustomerDTO> customerList = new ArrayList<>(); private List<DropdownDTO> customerList = new ArrayList<>();
private List<ProductDTO> productList = new ArrayList<>(); private List<ProductDTO> productList = new ArrayList<>();
private List<SaleDTO.SaleItemDTO> cartItems = new ArrayList<>(); private List<SaleDTO.SaleItemDTO> cartItems = new ArrayList<>();
@@ -104,30 +104,24 @@ public class SaleDetailFragment extends Fragment {
} }
private void loadStores() { private void loadStores() {
storeViewModel.getAllStores(0, 50).observe(getViewLifecycleOwner(), resource -> { storeViewModel.getStoreDropdowns().observe(getViewLifecycleOwner(), resource -> {
if (resource != null && resource.status == Resource.Status.SUCCESS && resource.data != null) { if (resource != null && resource.status == Resource.Status.SUCCESS && resource.data != null) {
storeList = resource.data.getContent(); storeList = resource.data;
if (binding != null) { if (binding != null) {
SpinnerUtils.populateSpinner(requireContext(), binding.spinnerSaleStore, storeList, SpinnerUtils.populateSpinner(requireContext(), binding.spinnerSaleStore, storeList,
StoreDTO::getStoreName, "-- Select Store --", -1L, StoreDTO::getStoreId); DropdownDTO::getLabel, "-- Select Store --", -1L, DropdownDTO::getId);
}
} else if (storeList.isEmpty()) {
storeList = Collections.singletonList(new StoreDTO(1L, "Downtown Branch"));
if (binding != null) {
SpinnerUtils.populateSpinner(requireContext(), binding.spinnerSaleStore, storeList,
StoreDTO::getStoreName, "-- Select Store --", -1L, StoreDTO::getStoreId);
} }
} }
}); });
} }
private void loadCustomers() { private void loadCustomers() {
customerViewModel.getAllCustomers(0, 200).observe(getViewLifecycleOwner(), resource -> { customerViewModel.getCustomerDropdowns().observe(getViewLifecycleOwner(), resource -> {
if (resource != null && resource.status == Resource.Status.SUCCESS && resource.data != null) { if (resource != null && resource.status == Resource.Status.SUCCESS && resource.data != null) {
customerList = resource.data.getContent(); customerList = resource.data;
if (binding != null) { if (binding != null) {
SpinnerUtils.populateSpinner(requireContext(), binding.spinnerSaleCustomer, customerList, SpinnerUtils.populateSpinner(requireContext(), binding.spinnerSaleCustomer, customerList,
CustomerDTO::getFullName, "-- No Customer --", -1L, CustomerDTO::getCustomerId); DropdownDTO::getLabel, "-- No Customer --", -1L, DropdownDTO::getId);
} }
} }
}); });
@@ -275,18 +269,18 @@ public class SaleDetailFragment extends Fragment {
return; return;
} }
StoreDTO store = storeList.get(binding.spinnerSaleStore.getSelectedItemPosition() - 1); DropdownDTO store = storeList.get(binding.spinnerSaleStore.getSelectedItemPosition() - 1);
String payment = PAYMENT_METHODS[binding.spinnerPaymentMethod.getSelectedItemPosition()]; String payment = PAYMENT_METHODS[binding.spinnerPaymentMethod.getSelectedItemPosition()];
// Optional customer // Optional customer
Long customerId = null; Long customerId = null;
if (binding.spinnerSaleCustomer.getSelectedItemPosition() > 0) { if (binding.spinnerSaleCustomer.getSelectedItemPosition() > 0) {
customerId = customerList.get(binding.spinnerSaleCustomer.getSelectedItemPosition() - 1) customerId = customerList.get(binding.spinnerSaleCustomer.getSelectedItemPosition() - 1)
.getCustomerId(); .getId();
} }
SaleDTO dto = new SaleDTO( SaleDTO dto = new SaleDTO(
store.getStoreId(), store.getId(),
payment, payment,
cartItems, cartItems,
false, false,

View File

@@ -4,9 +4,12 @@ import androidx.lifecycle.LiveData;
import com.example.petstoremobile.api.CustomerApi; import com.example.petstoremobile.api.CustomerApi;
import com.example.petstoremobile.dtos.CustomerDTO; import com.example.petstoremobile.dtos.CustomerDTO;
import com.example.petstoremobile.dtos.DropdownDTO;
import com.example.petstoremobile.dtos.PageResponse; import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.utils.Resource; import com.example.petstoremobile.utils.Resource;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@@ -33,4 +36,11 @@ public class CustomerRepository extends BaseRepository {
public LiveData<Resource<CustomerDTO>> getCustomerById(Long id) { public LiveData<Resource<CustomerDTO>> getCustomerById(Long id) {
return executeCall(customerApi.getCustomerById(id)); return executeCall(customerApi.getCustomerById(id));
} }
}
/**
* Retrieves a list of customer dropdowns from the API.
*/
public LiveData<Resource<List<DropdownDTO>>> getCustomerDropdowns() {
return executeCall(customerApi.getCustomerDropdowns());
}
}

View File

@@ -4,10 +4,13 @@ import androidx.lifecycle.LiveData;
import com.example.petstoremobile.api.PetApi; import com.example.petstoremobile.api.PetApi;
import com.example.petstoremobile.dtos.BulkDeleteRequest; import com.example.petstoremobile.dtos.BulkDeleteRequest;
import com.example.petstoremobile.dtos.DropdownDTO;
import com.example.petstoremobile.dtos.PageResponse; import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.dtos.PetDTO; import com.example.petstoremobile.dtos.PetDTO;
import com.example.petstoremobile.utils.Resource; import com.example.petstoremobile.utils.Resource;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@@ -30,6 +33,20 @@ public class PetRepository extends BaseRepository {
return executeCall(petApi.getAllPets(page, size, query, status, species, storeId, customerId, sort)); return executeCall(petApi.getAllPets(page, size, query, status, species, storeId, customerId, sort));
} }
/**
* Retrieves a list of pets for a specific customer from the dropdowns API.
*/
public LiveData<Resource<List<DropdownDTO>>> getCustomerPets(Long customerId) {
return executeCall(petApi.getCustomerPets(customerId));
}
/**
* Retrieves a list of pets available for adoption from the dropdowns API.
*/
public LiveData<Resource<List<DropdownDTO>>> getAdoptionPets() {
return executeCall(petApi.getAdoptionPets());
}
/** /**
* Retrieves a specific pet by its ID from the API. * Retrieves a specific pet by its ID from the API.
*/ */

View File

@@ -30,6 +30,13 @@ public class StoreRepository extends BaseRepository {
return executeCall(storeApi.getAllStores(page, size)); return executeCall(storeApi.getAllStores(page, size));
} }
/**
* Retrieves a list of store dropdowns from the API.
*/
public LiveData<Resource<List<DropdownDTO>>> getStoreDropdowns() {
return executeCall(storeApi.getStoreDropdowns());
}
/** /**
* Retrieves a list of employees for a specific store from the dropdowns API. * Retrieves a list of employees for a specific store from the dropdowns API.
*/ */

View File

@@ -4,10 +4,13 @@ import androidx.lifecycle.LiveData;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
import com.example.petstoremobile.dtos.CustomerDTO; import com.example.petstoremobile.dtos.CustomerDTO;
import com.example.petstoremobile.dtos.DropdownDTO;
import com.example.petstoremobile.dtos.PageResponse; import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.repositories.CustomerRepository; import com.example.petstoremobile.repositories.CustomerRepository;
import com.example.petstoremobile.utils.Resource; import com.example.petstoremobile.utils.Resource;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import dagger.hilt.android.lifecycle.HiltViewModel; import dagger.hilt.android.lifecycle.HiltViewModel;
@@ -34,4 +37,11 @@ public class CustomerViewModel extends ViewModel {
public LiveData<Resource<CustomerDTO>> getCustomerById(Long id) { public LiveData<Resource<CustomerDTO>> getCustomerById(Long id) {
return repository.getCustomerById(id); return repository.getCustomerById(id);
} }
}
/**
* Retrieves a list of customer dropdowns from the repository.
*/
public LiveData<Resource<List<DropdownDTO>>> getCustomerDropdowns() {
return repository.getCustomerDropdowns();
}
}

View File

@@ -4,6 +4,7 @@ import androidx.lifecycle.LiveData;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
import com.example.petstoremobile.dtos.BulkDeleteRequest; import com.example.petstoremobile.dtos.BulkDeleteRequest;
import com.example.petstoremobile.dtos.DropdownDTO;
import com.example.petstoremobile.dtos.PageResponse; import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.dtos.PetDTO; import com.example.petstoremobile.dtos.PetDTO;
import com.example.petstoremobile.repositories.PetRepository; import com.example.petstoremobile.repositories.PetRepository;
@@ -32,6 +33,20 @@ public class PetViewModel extends ViewModel {
return repository.getAllPets(page, size, query, status, species, storeId, customerId, sort); return repository.getAllPets(page, size, query, status, species, storeId, customerId, sort);
} }
/**
* Retrieves a list of pets for a specific customer from the repository.
*/
public LiveData<Resource<List<DropdownDTO>>> getCustomerPets(Long customerId) {
return repository.getCustomerPets(customerId);
}
/**
* Retrieves a list of pets available for adoption from the repository.
*/
public LiveData<Resource<List<DropdownDTO>>> getAdoptionPets() {
return repository.getAdoptionPets();
}
/** /**
* Retrieves a single pet by its ID. * Retrieves a single pet by its ID.
*/ */

View File

@@ -31,6 +31,13 @@ public class StoreViewModel extends ViewModel {
return repository.getAllStores(page, size); return repository.getAllStores(page, size);
} }
/**
* Fetches a list of store dropdowns from the repository.
*/
public LiveData<Resource<List<DropdownDTO>>> getStoreDropdowns() {
return repository.getStoreDropdowns();
}
/** /**
* Fetches a list of employees for a specific store. * Fetches a list of employees for a specific store.
*/ */