package com.system.care.health.HealthAndCareSystem.repositories;
import com.system.care.health.HealthAndCareSystem.dtos.consultation.ConsultationRegisterDT0;
import com.system.care.health.HealthAndCareSystem.dtos.doctor.DoctorListDTO;
import com.system.care.health.HealthAndCareSystem.enums.Specialty;
import com.system.care.health.HealthAndCareSystem.models.DoctorModel;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.time.LocalDateTime;
import java.util.List;
public interface DoctorRepository extends JpaRepository<DoctorModel, Long> {
@Query("SELECT d FROM Doctor d WHERE d.active = true")
Page<DoctorModel> findAll(Pageable pageable);
@Query("""
SELECT d FROM DoctorModel d
WHERE
d.active = 1
AND
d.specialty = :specialty
AND
d.id NOT IN(
SELECT c.doctor.id FROM Consultation c
WHERE
c.date = :dateTime
)
ORDER BY RAND()
limit 1
""")
DoctorModel chooseRandomDoctorFreeOnDate(Specialty specialty, LocalDateTime data);
}
log: 2023-07-29T16:41:17.997-03:00 WARN 13352 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'doctorController': Unsatisfied dependency expressed through field 'repository': Error creating bean with name 'doctorRepository' defined in com.system.care.health.HealthAndCareSystem.repositories.DoctorRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Could not create query for public abstract com.system.care.health.HealthAndCareSystem.models.DoctorModel com.system.care.health.HealthAndCareSystem.repositories.DoctorRepository.chooseRandomDoctorFreeOnDate(com.system.care.health.HealthAndCareSystem.enums.Specialty,java.time.LocalDateTime); Reason: Using named parameters for method public abstract com.system.care.health.HealthAndCareSystem.models.DoctorModel com.system.care.health.HealthAndCareSystem.repositories.DoctorRepository.chooseRandomDoctorFreeOnDate(com.system.care.health.HealthAndCareSystem.enums.Specialty,java.time.LocalDateTime) but parameter 'Optional[data]' not found in annotated query 'SELECT d FROM DoctorModel d WHERE d.active = 1 AND d.specialty = :specialty AND d.id NOT IN( SELECT c.doctor.id FROM Consultation c WHERE c.date = :dateTime ) ORDER BY RAND() limit 1 ' 2023-07-29T16:41:17.997-03:00 INFO 13352 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default' 2023-07-29T16:41:18.000-03:00 INFO 13352 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2023-07-29T16:41:18.007-03:00 INFO 13352 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed. 2023-07-29T16:41:18.011-03:00 INFO 13352 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2023-07-29T16:41:18.040-03:00 INFO 13352 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger :
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2023-07-29T16:41:18.071-03:00 ERROR 13352 --- [ main] o.s.boot.SpringApplication : Application run failed