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;
import com.example.petstoremobile.dtos.CustomerDTO;
import com.example.petstoremobile.dtos.DropdownDTO;
import com.example.petstoremobile.dtos.PageResponse;
import java.util.List;
@@ -18,4 +19,7 @@ public interface CustomerApi {
@GET("api/v1/customers/{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;
import com.example.petstoremobile.dtos.BulkDeleteRequest;
import com.example.petstoremobile.dtos.DropdownDTO;
import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.dtos.PetDTO;
import java.util.List;
import okhttp3.MultipartBody;
import retrofit2.Call;
import retrofit2.http.Body;
@@ -35,6 +38,12 @@ public interface PetApi {
@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("api/v1/pets/{id}")
Call<PetDTO> getPetById(@Path("id") Long id);

View File

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

View File

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

View File

@@ -14,6 +14,7 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.fragment.NavHostFragment;
import com.example.petstoremobile.databinding.FragmentInventoryDetailBinding;
import com.example.petstoremobile.dtos.DropdownDTO;
import com.example.petstoremobile.dtos.InventoryDTO;
import com.example.petstoremobile.dtos.ProductDTO;
import com.example.petstoremobile.dtos.StoreDTO;
@@ -46,7 +47,7 @@ public class InventoryDetailFragment extends Fragment {
private long preselectedStoreId = -1;
private long preselectedProductId = -1;
private List<StoreDTO> storeList = new ArrayList<>();
private List<DropdownDTO> storeList = 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.
*/
private void loadStores() {
storeViewModel.getAllStores(0, 100).observe(getViewLifecycleOwner(), resource -> {
storeViewModel.getStoreDropdowns().observe(getViewLifecycleOwner(), resource -> {
if (resource.status == Resource.Status.SUCCESS && resource.data != null) {
storeList = resource.data.getContent();
storeList = resource.data;
refreshStoreSpinner();
}
});
@@ -113,8 +114,8 @@ public class InventoryDetailFragment extends Fragment {
private void refreshStoreSpinner() {
SpinnerUtils.populateSpinner(requireContext(), binding.spinnerInventoryStore, storeList,
StoreDTO::getStoreName, "-- Select Store --",
preselectedStoreId, StoreDTO::getStoreId);
DropdownDTO::getLabel, "-- Select Store --",
preselectedStoreId, DropdownDTO::getId);
}
/**
@@ -199,10 +200,10 @@ public class InventoryDetailFragment extends Fragment {
}
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);
InventoryDTO request = new InventoryDTO(product.getProdId(), store.getStoreId(), quantity);
InventoryDTO request = new InventoryDTO(product.getProdId(), store.getId(), quantity);
setButtonsEnabled(false);
if (isEditing) {

View File

@@ -18,9 +18,8 @@ import android.widget.Toast;
import com.example.petstoremobile.R;
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.StoreDTO;
import com.example.petstoremobile.utils.ActivityLogger;
import com.example.petstoremobile.utils.DialogUtils;
import com.example.petstoremobile.utils.InputValidator;
@@ -49,8 +48,8 @@ public class PetDetailFragment extends Fragment {
private PetViewModel viewModel;
private CustomerViewModel customerViewModel;
private StoreViewModel storeViewModel;
private List<CustomerDTO> customerList = new ArrayList<>();
private List<StoreDTO> storeList = new ArrayList<>();
private List<DropdownDTO> customerList = new ArrayList<>();
private List<DropdownDTO> storeList = new ArrayList<>();
private Long selectedCustomerId = null;
private Long selectedStoreId = null;
@@ -113,14 +112,14 @@ public class PetDetailFragment extends Fragment {
Long customerId = null;
int customerPos = binding.spinnerCustomer.getSelectedItemPosition();
if (customerPos > 0) { // 0 means no customer for pet
customerId = customerList.get(customerPos - 1).getCustomerId();
customerId = customerList.get(customerPos - 1).getId();
}
// Get selected store
Long storeId = null;
int storePos = binding.spinnerStore.getSelectedItemPosition();
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
@@ -277,9 +276,9 @@ public class PetDetailFragment extends Fragment {
* Fetches the list of customers and populates the spinner.
*/
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) {
customerList = resource.data.getContent();
customerList = resource.data;
updateCustomerSpinnerSelection();
}
});
@@ -289,9 +288,9 @@ public class PetDetailFragment extends Fragment {
* Fetches the list of stores and populates the spinner.
*/
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) {
storeList = resource.data.getContent();
storeList = resource.data;
updateStoreSpinnerSelection();
}
});
@@ -305,10 +304,10 @@ public class PetDetailFragment extends Fragment {
requireContext(),
binding.spinnerCustomer,
customerList,
CustomerDTO::getFullName,
DropdownDTO::getLabel,
"No Owner",
selectedCustomerId,
CustomerDTO::getCustomerId
DropdownDTO::getId
);
}
@@ -320,10 +319,10 @@ public class PetDetailFragment extends Fragment {
requireContext(),
binding.spinnerStore,
storeList,
StoreDTO::getStoreName,
DropdownDTO::getLabel,
"None",
selectedStoreId,
StoreDTO::getStoreId
DropdownDTO::getId
);
}
@@ -379,4 +378,4 @@ public class PetDetailFragment extends Fragment {
((TextView) selectedView).setError(null);
}
}
}
}

View File

@@ -31,8 +31,8 @@ public class SaleDetailFragment extends Fragment {
private boolean viewOnly = false;
private long saleId = -1;
private List<StoreDTO> storeList = new ArrayList<>();
private List<CustomerDTO> customerList = new ArrayList<>();
private List<DropdownDTO> storeList = new ArrayList<>();
private List<DropdownDTO> customerList = new ArrayList<>();
private List<ProductDTO> productList = new ArrayList<>();
private List<SaleDTO.SaleItemDTO> cartItems = new ArrayList<>();
@@ -104,30 +104,24 @@ public class SaleDetailFragment extends Fragment {
}
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) {
storeList = resource.data.getContent();
storeList = resource.data;
if (binding != null) {
SpinnerUtils.populateSpinner(requireContext(), binding.spinnerSaleStore, storeList,
StoreDTO::getStoreName, "-- Select Store --", -1L, StoreDTO::getStoreId);
}
} 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);
DropdownDTO::getLabel, "-- Select Store --", -1L, DropdownDTO::getId);
}
}
});
}
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) {
customerList = resource.data.getContent();
customerList = resource.data;
if (binding != null) {
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;
}
StoreDTO store = storeList.get(binding.spinnerSaleStore.getSelectedItemPosition() - 1);
DropdownDTO store = storeList.get(binding.spinnerSaleStore.getSelectedItemPosition() - 1);
String payment = PAYMENT_METHODS[binding.spinnerPaymentMethod.getSelectedItemPosition()];
// Optional customer
Long customerId = null;
if (binding.spinnerSaleCustomer.getSelectedItemPosition() > 0) {
customerId = customerList.get(binding.spinnerSaleCustomer.getSelectedItemPosition() - 1)
.getCustomerId();
.getId();
}
SaleDTO dto = new SaleDTO(
store.getStoreId(),
store.getId(),
payment,
cartItems,
false,

View File

@@ -4,9 +4,12 @@ import androidx.lifecycle.LiveData;
import com.example.petstoremobile.api.CustomerApi;
import com.example.petstoremobile.dtos.CustomerDTO;
import com.example.petstoremobile.dtos.DropdownDTO;
import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.utils.Resource;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -33,4 +36,11 @@ public class CustomerRepository extends BaseRepository {
public LiveData<Resource<CustomerDTO>> getCustomerById(Long 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.dtos.BulkDeleteRequest;
import com.example.petstoremobile.dtos.DropdownDTO;
import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.dtos.PetDTO;
import com.example.petstoremobile.utils.Resource;
import java.util.List;
import javax.inject.Inject;
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));
}
/**
* 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.
*/

View File

@@ -30,6 +30,13 @@ public class StoreRepository extends BaseRepository {
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.
*/

View File

@@ -4,10 +4,13 @@ import androidx.lifecycle.LiveData;
import androidx.lifecycle.ViewModel;
import com.example.petstoremobile.dtos.CustomerDTO;
import com.example.petstoremobile.dtos.DropdownDTO;
import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.repositories.CustomerRepository;
import com.example.petstoremobile.utils.Resource;
import java.util.List;
import javax.inject.Inject;
import dagger.hilt.android.lifecycle.HiltViewModel;
@@ -34,4 +37,11 @@ public class CustomerViewModel extends ViewModel {
public LiveData<Resource<CustomerDTO>> getCustomerById(Long 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 com.example.petstoremobile.dtos.BulkDeleteRequest;
import com.example.petstoremobile.dtos.DropdownDTO;
import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.dtos.PetDTO;
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);
}
/**
* 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.
*/

View File

@@ -31,6 +31,13 @@ public class StoreViewModel extends ViewModel {
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.
*/