Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Bug no escolherMedicoAleatorioLivreNaData

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

3 respostas
solução!

Oi!

Na sua query tem esse trecho:

c.date = :dateTime

O parâmetro foi chamado de dateTime, mas na assinatura do método você colocou o nome data:

DoctorModel chooseRandomDoctorFreeOnDate(Specialty specialty, LocalDateTime data);

Deveria ser:

DoctorModel chooseRandomDoctorFreeOnDate(Specialty specialty, LocalDateTime dateTime);

Continuou com outro erro agr

2023-07-31T20:54:32.813-03:00 WARN 23240 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'medicoController': Unsatisfied dependency expressed through field 'repository': Error creating bean with name 'medicoRepository' defined in com.system.care.health.HealthAndCareSystem.repositories.MedicoRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Could not create query for public abstract com.system.care.health.HealthAndCareSystem.models.Medico com.system.care.health.HealthAndCareSystem.repositories.MedicoRepository.chooseRandomDoctorFreeOnDate(com.system.care.health.HealthAndCareSystem.enums.Especialidade,java.time.LocalDateTime); Reason: Using named parameters for method public abstract com.system.care.health.HealthAndCareSystem.models.Medico com.system.care.health.HealthAndCareSystem.repositories.MedicoRepository.chooseRandomDoctorFreeOnDate(com.system.care.health.HealthAndCareSystem.enums.Especialidade,java.time.LocalDateTime) but parameter 'Optional[dateTimeTa]' not found in annotated query ' SELECT d FROM Doctor d WHERE d.active = true AND d.id NOT IN ( SELECT c.id_doctor FROM Consultation c WHERE c.date = :dateTime ) AND d.especialidade = :especialidade ORDER BY RAND() LIMIT 1 ' 2023-07-31T20:54:32.813-03:00 INFO 23240 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default' 2023-07-31T20:54:32.816-03:00 INFO 23240 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2023-07-31T20:54:32.824-03:00 INFO 23240 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed. 2023-07-31T20:54:32.828-03:00 INFO 23240 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2023-07-31T20:54:32.857-03:00 INFO 23240 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2023-07-31T20:54:32.974-03:00 ERROR 23240 --- [ main] o.s.boot.SpringApplication : Application run failed

org.s

Manda aqui como ficou o código do seu medicoRepository