updard Adoptions in andriod for new backend

This commit is contained in:
Alex
2026-04-07 14:35:57 -06:00
parent baa143ff00
commit 679c451c04
5 changed files with 154 additions and 11 deletions

View File

@@ -46,6 +46,7 @@ public class AdoptionAdapter extends RecyclerView.Adapter<AdoptionAdapter.Adopti
binding.tvAdoptionCustomerName.setText(a.getCustomerName() != null ? a.getCustomerName() : "");
binding.tvAdoptionPetName.setText("Pet: " + (a.getPetName() != null ? a.getPetName() : ""));
binding.tvAdoptionStaffName.setText("Staff: " + (a.getEmployeeName() != null ? a.getEmployeeName() : "N/A"));
binding.tvAdoptionDate.setText("Date: " + (a.getAdoptionDate() != null ? a.getAdoptionDate() : ""));
binding.tvAdoptionFee.setText(a.getAdoptionFee() != null ? "$" + a.getAdoptionFee() : "");

View File

@@ -18,80 +18,127 @@ public class AdoptionDTO {
private String createdAt;
private String updatedAt;
public AdoptionDTO(Long petId, Long customerId, Long sourceStoreId, String adoptionDate, String adoptionStatus) {
this.petId = petId;
this.customerId = customerId;
this.sourceStoreId = sourceStoreId;
this.adoptionDate = adoptionDate;
this.adoptionStatus = adoptionStatus;
}
public AdoptionDTO() {}
public AdoptionDTO(Long petId, Long customerId, Long employeeId, Long sourceStoreId, String adoptionDate, String adoptionStatus) {
public AdoptionDTO(Long petId, Long customerId, Long employeeId, Long sourceStoreId, String adoptionDate, String adoptionStatus, BigDecimal adoptionFee) {
this.petId = petId;
this.customerId = customerId;
this.employeeId = employeeId;
this.sourceStoreId = sourceStoreId;
this.adoptionDate = adoptionDate;
this.adoptionStatus = adoptionStatus;
this.adoptionFee = adoptionFee;
}
public Long getAdoptionId() {
return adoptionId;
}
public void setAdoptionId(Long adoptionId) {
this.adoptionId = adoptionId;
}
public Long getPetId() {
return petId;
}
public void setPetId(Long petId) {
this.petId = petId;
}
public String getPetName() {
return petName;
}
public void setPetName(String petName) {
this.petName = petName;
}
public Long getCustomerId() {
return customerId;
}
public void setCustomerId(Long customerId) {
this.customerId = customerId;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public Long getEmployeeId() {
return employeeId;
}
public void setEmployeeId(Long employeeId) {
this.employeeId = employeeId;
}
public String getEmployeeName() {
return employeeName;
}
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
public Long getSourceStoreId() {
return sourceStoreId;
}
public void setSourceStoreId(Long sourceStoreId) {
this.sourceStoreId = sourceStoreId;
}
public String getSourceStoreName() {
return sourceStoreName;
}
public void setSourceStoreName(String sourceStoreName) {
this.sourceStoreName = sourceStoreName;
}
public String getAdoptionDate() {
return adoptionDate;
}
public void setAdoptionDate(String adoptionDate) {
this.adoptionDate = adoptionDate;
}
public String getAdoptionStatus() {
return adoptionStatus;
}
public String getStatus() {
return adoptionStatus;
public void setAdoptionStatus(String adoptionStatus) {
this.adoptionStatus = adoptionStatus;
}
public BigDecimal getAdoptionFee() {
return adoptionFee;
}
public void setAdoptionFee(BigDecimal adoptionFee) {
this.adoptionFee = adoptionFee;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
public String getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(String updatedAt) {
this.updatedAt = updatedAt;
}
}

View File

@@ -19,7 +19,9 @@ import com.example.petstoremobile.viewmodels.AdoptionViewModel;
import com.example.petstoremobile.viewmodels.CustomerViewModel;
import com.example.petstoremobile.viewmodels.PetViewModel;
import com.example.petstoremobile.viewmodels.StoreViewModel;
import com.example.petstoremobile.viewmodels.UserViewModel;
import java.math.BigDecimal;
import java.util.*;
import dagger.hilt.android.AndroidEntryPoint;
@@ -37,10 +39,12 @@ public class AdoptionDetailFragment extends Fragment {
private long preselectedPetId = -1;
private long preselectedCustomerId = -1;
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<UserDTO> employeeList = new ArrayList<>();
private final String[] STATUSES = {"Pending", "Completed", "Cancelled"};
@@ -48,6 +52,7 @@ public class AdoptionDetailFragment extends Fragment {
private PetViewModel petViewModel;
private CustomerViewModel customerViewModel;
private StoreViewModel storeViewModel;
private UserViewModel userViewModel;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -56,6 +61,7 @@ public class AdoptionDetailFragment extends Fragment {
petViewModel = new ViewModelProvider(this).get(PetViewModel.class);
customerViewModel = new ViewModelProvider(this).get(CustomerViewModel.class);
storeViewModel = new ViewModelProvider(this).get(StoreViewModel.class);
userViewModel = new ViewModelProvider(this).get(UserViewModel.class);
}
@Override
@@ -113,6 +119,7 @@ public class AdoptionDetailFragment extends Fragment {
loadPets();
loadCustomers();
loadStores();
loadEmployees();
}
/**
@@ -179,6 +186,27 @@ public class AdoptionDetailFragment extends Fragment {
preselectedStoreId, StoreDTO::getStoreId);
}
/**
* Loads the list of employees from the API.
*/
private void loadEmployees() {
userViewModel.getUsers("STAFF", 0, 100).observe(getViewLifecycleOwner(), resource -> {
if (resource.status == Resource.Status.SUCCESS && resource.data != null) {
employeeList = resource.data.getContent();
refreshEmployeeSpinner();
}
});
}
/**
* Populates the employee selection spinner with data.
*/
private void refreshEmployeeSpinner() {
SpinnerUtils.populateSpinner(requireContext(), binding.spinnerAdoptionEmployee, employeeList,
UserDTO::getFullName, "-- Select Staff --",
preselectedEmployeeId, UserDTO::getId);
}
/**
* Handles arguments to determine if the fragment is in edit or add mode.
*/
@@ -210,12 +238,16 @@ public class AdoptionDetailFragment extends Fragment {
preselectedPetId = a.getPetId() != null ? a.getPetId() : -1;
preselectedCustomerId = a.getCustomerId() != null ? a.getCustomerId() : -1;
preselectedStoreId = a.getSourceStoreId() != null ? a.getSourceStoreId() : -1;
preselectedEmployeeId = a.getEmployeeId() != null ? a.getEmployeeId() : -1;
binding.etAdoptionDate.setText(a.getAdoptionDate());
binding.etAdoptionFee.setText(a.getAdoptionFee() != null ? a.getAdoptionFee().toString() : "");
SpinnerUtils.setSelectionByValue(binding.spinnerAdoptionStatus, a.getAdoptionStatus());
refreshPetSpinner();
refreshCustomerSpinner();
refreshStoreSpinner();
refreshEmployeeSpinner();
} else if (resource.status == Resource.Status.ERROR) {
Toast.makeText(getContext(), "Failed to load adoption: " + resource.message, Toast.LENGTH_SHORT).show();
}
@@ -240,17 +272,36 @@ public class AdoptionDetailFragment extends Fragment {
Toast.makeText(getContext(), "Select a date", Toast.LENGTH_SHORT).show(); return;
}
BigDecimal fee = BigDecimal.ZERO;
String feeStr = binding.etAdoptionFee.getText().toString().trim();
if (!feeStr.isEmpty()) {
try {
fee = new BigDecimal(feeStr);
} catch (NumberFormatException e) {
Toast.makeText(getContext(), "Invalid fee format", Toast.LENGTH_SHORT).show();
return;
}
}
CustomerDTO customer = customerList.get(binding.spinnerAdoptionCustomer.getSelectedItemPosition() - 1);
PetDTO pet = petList.get(binding.spinnerAdoptionPet.getSelectedItemPosition() - 1);
StoreDTO store = storeList.get(binding.spinnerAdoptionStore.getSelectedItemPosition() - 1);
Long employeeId = null;
if (binding.spinnerAdoptionEmployee.getSelectedItemPosition() > 0) {
employeeId = employeeList.get(binding.spinnerAdoptionEmployee.getSelectedItemPosition() - 1).getId();
}
String status = STATUSES[binding.spinnerAdoptionStatus.getSelectedItemPosition()];
AdoptionDTO dto = new AdoptionDTO(
pet.getPetId(),
customer.getCustomerId(),
employeeId,
store.getStoreId(),
date,
status
status,
fee
);
if (isEditing) {

View File

@@ -95,6 +95,21 @@
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"/>
<!-- Employee -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Handled By (Staff)"
android:textColor="@color/text_dark"
android:textSize="12sp"
android:layout_marginBottom="4dp"/>
<Spinner
android:id="@+id/spinnerAdoptionEmployee"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -129,6 +144,23 @@
android:drawableEnd="@android:drawable/ic_menu_my_calendar"
android:layout_marginBottom="16dp"/>
<!-- Adoption Fee -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Adoption Fee"
android:textColor="@color/text_dark"
android:textSize="12sp"
android:layout_marginBottom="4dp"/>
<EditText
android:id="@+id/etAdoptionFee"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="0.00"
android:inputType="numberDecimal"
android:layout_marginBottom="16dp"/>
<!-- Status -->
<TextView
android:layout_width="wrap_content"

View File

@@ -53,6 +53,18 @@
android:textColor="#888888"
android:textSize="14sp" />
<TextView
android:id="@+id/tvAdoptionStaffName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:ellipsize="end"
android:maxLines="1"
android:text="Staff: "
android:textColor="#888888"
android:textSize="13sp"
android:textStyle="italic" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"