fix six app bugs

This commit is contained in:
2026-04-16 07:55:13 -06:00
parent f61a765624
commit 7b4874b8b1
7 changed files with 21 additions and 13 deletions

View File

@@ -56,7 +56,8 @@ public class AiChatController {
List<Pet> userPets;
try {
userPets = petRepository.findAllByOwner_IdOrderByPetNameAsc(user.getId());
userPets = petRepository.findAllByOwner_IdAndPetStatusInOrderByPetNameAsc(
user.getId(), List.of("Adopted", "Owned"));
}
catch (Exception e) {

View File

@@ -53,5 +53,8 @@ public interface AppointmentRepository extends JpaRepository<Appointment, Long>
List<Appointment> findByPet_Id(Long petId);
@Query("SELECT a FROM Appointment a JOIN FETCH a.service WHERE a.pet.petId = :petId AND a.appointmentDate = :date AND LOWER(a.appointmentStatus) NOT IN ('cancelled', 'missed')")
List<Appointment> findByPetIdAndAppointmentDate(@Param("petId") Long petId, @Param("date") LocalDate date);
List<Appointment> findByAppointmentDateAndAppointmentStatusIgnoreCase(LocalDate date, String status);
}

View File

@@ -37,6 +37,7 @@ public interface PetRepository extends JpaRepository<Pet, Long> {
List<Pet> findAdoptablePetsByStore(@Param("storeId") Long storeId);
List<Pet> findAllByOwner_IdOrderByPetNameAsc(Long ownerId);
List<Pet> findAllByOwner_IdAndPetStatusInOrderByPetNameAsc(Long ownerId, List<String> statuses);
Optional<Pet> findByIdAndOwner_Id(Long id, Long ownerId);
@Lock(LockModeType.PESSIMISTIC_WRITE)

View File

@@ -132,6 +132,7 @@ public class AppointmentService {
validateStoreAccess(store.getStoreId(), authenticatedUser);
validatePetServiceCompatibility(pet, service);
validateAvailability(employee, service, request.getAppointmentDate(), request.getAppointmentTime(), null);
validatePetAvailability(pet, service, request.getAppointmentDate(), request.getAppointmentTime(), null);
Appointment appointment = new Appointment();
appointment.setCustomer(customer);
@@ -172,6 +173,7 @@ public class AppointmentService {
validateStoreAccess(store.getStoreId(), authenticatedUser);
validatePetServiceCompatibility(pet, service);
validateAvailability(employee, service, request.getAppointmentDate(), request.getAppointmentTime(), id);
validatePetAvailability(pet, service, request.getAppointmentDate(), request.getAppointmentTime(), id);
appointment.setCustomer(customer);
appointment.setStore(store);
@@ -387,6 +389,15 @@ public class AppointmentService {
return true;
}
private void validatePetAvailability(Pet pet, com.petshop.backend.entity.Service service, LocalDate date, LocalTime time, Long appointmentIdToIgnore) {
if (pet == null) return;
List<Appointment> existingAppointments = appointmentRepository
.findByPetIdAndAppointmentDate(pet.getPetId(), date);
if (!isSlotAvailable(existingAppointments, service, time, appointmentIdToIgnore)) {
throw new IllegalArgumentException("This pet already has an appointment during this time slot");
}
}
private void validateSpeciesServiceCompatibility(Pet pet, com.petshop.backend.entity.Service service) {
if (pet == null || service == null) return;
String species = pet.getPetSpecies();