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