added pending status on pets andiord, also made pets automatically switch to pending when an adoption is in pending
This commit is contained in:
@@ -104,10 +104,20 @@ public class PetAdapter extends RecyclerView.Adapter<PetAdapter.PetViewHolder> i
|
||||
binding.tvPetStatus.setText(pet.getPetStatus());
|
||||
|
||||
//Set the status color depending on availability. If available, green, otherwise red
|
||||
if (pet.getPetStatus() != null && pet.getPetStatus().equals("Available")) {
|
||||
if (pet.getPetStatus() != null) {
|
||||
switch (pet.getPetStatus()) {
|
||||
case "Available":
|
||||
binding.tvPetStatus.setBackgroundColor(Color.parseColor("#4CAF50"));
|
||||
} else {
|
||||
break;
|
||||
case "Pending":
|
||||
binding.tvPetStatus.setBackgroundColor(Color.parseColor("#FF9800"));
|
||||
break;
|
||||
default:
|
||||
binding.tvPetStatus.setBackgroundColor(Color.parseColor("#F44336"));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
binding.tvPetStatus.setBackgroundColor(Color.parseColor("#9E9E9E"));
|
||||
}
|
||||
|
||||
// Load pet image using Glide
|
||||
|
||||
@@ -136,7 +136,7 @@ public class PetFragment extends Fragment implements PetAdapter.OnPetClickListen
|
||||
}
|
||||
|
||||
private void setupStatusFilter() {
|
||||
String[] statuses = {"All Statuses", "Available", "Adopted", "Owned"};
|
||||
String[] statuses = {"All Statuses", "Available", "Adopted", "Owned", "Pending"};
|
||||
SpinnerUtils.setupStringFilterSpinner(requireContext(), binding.spinnerStatus, statuses, this::loadPetData);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ public class PetDetailViewModel extends ViewModel {
|
||||
private static final String STATUS_AVAILABLE = "Available";
|
||||
private static final String STATUS_ADOPTED = "Adopted";
|
||||
private static final String STATUS_OWNED = "Owned";
|
||||
private static final String STATUS_PENDING = "Pending";
|
||||
|
||||
private final PetRepository petRepository;
|
||||
private final CustomerRepository customerRepository;
|
||||
@@ -253,6 +254,7 @@ public class PetDetailViewModel extends ViewModel {
|
||||
String normalized = status.trim();
|
||||
if (STATUS_ADOPTED.equalsIgnoreCase(normalized)) return STATUS_ADOPTED;
|
||||
if (STATUS_OWNED.equalsIgnoreCase(normalized)) return STATUS_OWNED;
|
||||
if (STATUS_PENDING.equalsIgnoreCase(normalized)) return STATUS_PENDING;
|
||||
return STATUS_AVAILABLE;
|
||||
}
|
||||
|
||||
@@ -290,7 +292,7 @@ public class PetDetailViewModel extends ViewModel {
|
||||
public boolean isStoreEnabled = true;
|
||||
public String modeTitle = "Add Pet";
|
||||
public String saveButtonText = "Add";
|
||||
public String[] availableStatuses = new String[]{STATUS_AVAILABLE, STATUS_ADOPTED, STATUS_OWNED};
|
||||
public String[] availableStatuses = new String[]{STATUS_AVAILABLE, STATUS_ADOPTED, STATUS_OWNED, STATUS_PENDING};
|
||||
public String selectedStatus = STATUS_AVAILABLE;
|
||||
public String selectedSpecies = null;
|
||||
public Long selectedCustomerId = null;
|
||||
|
||||
@@ -19,7 +19,7 @@ public interface PetRepository extends JpaRepository<Pet, Long> {
|
||||
"WHERE LOWER(p.petStatus) = 'available' " +
|
||||
"AND NOT EXISTS (" +
|
||||
" SELECT 1 FROM Adoption a " +
|
||||
" WHERE a.pet = p AND LOWER(a.adoptionStatus) = 'completed'" +
|
||||
" WHERE a.pet = p AND (LOWER(a.adoptionStatus) = 'completed' OR LOWER(a.adoptionStatus) = 'pending')" +
|
||||
") " +
|
||||
"ORDER BY p.petName ASC")
|
||||
List<Pet> findAdoptablePetsOrderByPetNameAsc();
|
||||
@@ -29,7 +29,7 @@ public interface PetRepository extends JpaRepository<Pet, Long> {
|
||||
"AND (:storeId IS NULL OR p.store.storeId = :storeId) " +
|
||||
"AND NOT EXISTS (" +
|
||||
" SELECT 1 FROM Adoption a " +
|
||||
" WHERE a.pet = p AND LOWER(a.adoptionStatus) = 'completed'" +
|
||||
" WHERE a.pet = p AND (LOWER(a.adoptionStatus) = 'completed' OR LOWER(a.adoptionStatus) = 'pending')" +
|
||||
") " +
|
||||
"ORDER BY p.petName ASC")
|
||||
List<Pet> findAdoptablePetsByStore(@Param("storeId") Long storeId);
|
||||
|
||||
@@ -32,6 +32,7 @@ public class AdoptionService {
|
||||
private static final String ADOPTION_STATUS_MISSED = "Missed";
|
||||
private static final String PET_STATUS_AVAILABLE = "Available";
|
||||
private static final String PET_STATUS_ADOPTED = "Adopted";
|
||||
private static final String PET_STATUS_PENDING = "Pending";
|
||||
|
||||
private final AdoptionRepository adoptionRepository;
|
||||
private final PetRepository petRepository;
|
||||
@@ -263,10 +264,13 @@ public class AdoptionService {
|
||||
private void syncPetStatus(Pet pet, String adoptionStatus, Long adoptionId, User customer) {
|
||||
boolean completedElsewhere = adoptionId != null
|
||||
&& adoptionRepository.existsByPet_IdAndAdoptionStatusIgnoreCaseAndAdoptionIdNot(pet.getPetId(), ADOPTION_STATUS_COMPLETED, adoptionId);
|
||||
|
||||
if (ADOPTION_STATUS_COMPLETED.equalsIgnoreCase(adoptionStatus) || completedElsewhere) {
|
||||
pet.setPetStatus(PET_STATUS_ADOPTED);
|
||||
pet.setOwner(customer);
|
||||
pet.setStore(null);
|
||||
} else if (ADOPTION_STATUS_PENDING.equalsIgnoreCase(adoptionStatus)) {
|
||||
pet.setPetStatus(PET_STATUS_PENDING);
|
||||
} else {
|
||||
pet.setPetStatus(PET_STATUS_AVAILABLE);
|
||||
pet.setOwner(null);
|
||||
|
||||
Reference in New Issue
Block a user