added pending status on pets andiord, also made pets automatically switch to pending when an adoption is in pending

This commit is contained in:
Alex
2026-04-13 17:12:41 -06:00
parent 9fdb3087da
commit 688a04c3bc
5 changed files with 23 additions and 7 deletions

View File

@@ -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);

View File

@@ -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);