Estou desenvolvendo uma api spring boot e gostaria de padronizar as respostas dela, quando meu front-end faz uma requisição ela me devolve um json com dois tipos de formato nos objetos internos
Ex:
[
{
"id": 22,
"patient": null,
"dentist": {
"userId": "DTN-101001",
"document": "101001",
"name": "Roberto",
"surname": "Lakhroos",
"email": "[email protected]",
"telephone": "1140028922",
"cellphone": "11941170146",
"expertise": "Cirurgia",
"status": true
},
"dateTime": "2022-06-18 08:00:00",
"procedure": null,
"employee": {
"userId": "EPL-12345697810",
"document": "12345697810",
"name": "Roberto",
"surname": "Lakhroos",
"email": "[email protected]",
"telephone": "1140028922",
"cellphone": "11941170146",
"expertise": null,
"status": true
},
"status": true
},
{
"id": 23,
"patient": null,
"dentist": "DTN-101001",
"dateTime": "2022-06-18 09:00:00",
"procedure": null,
"employee": "EPL-12345697810",
"status": true
},
{
"id": 24,
"patient": null,
"dentist": "DTN-101001",
"dateTime": "2022-06-18 10:00:00",
"procedure": null,
"employee": "EPL-12345697810",
"status": true
}
]
Na primeira vez que um dentist ou employee aparecem eles vem completos, mas quando deveria aparecer os mesmos dados de novo a api devolve só o userId, como faço para que a resposta venha sempre com todos os dados?
Função no Controller:
@GetMapping("/list/{status}")
public List<Consult> findByStatus(@PathVariable("status") Boolean status) {
LOGGER.info("Search consults by status - " + status);
return this.consultRepository.findAllByStatus(status);
}
Função no Repository:
@Query("SELECT u from Consult u where u.status = :status")
public List<Consult> findAllByStatus(@Param("status") Boolean status);
Atributos da entidade:
@Table(name = "consults")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Consult {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@ManyToOne
@JoinColumn(name = "patient_cpf")
private Patient patient;
@ManyToOne
@JoinColumn(name = "dentist_id", nullable = false)
private User dentist;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime dateTime;
@ManyToOne
@JoinColumn(name = "procedure_id")
private Procedure procedure;
@ManyToOne
@JoinColumn(name = "employee_id", nullable = false)
private User employee;
private Boolean status;
//Getters, Setters, Contructors...
}
Código completo https://github.com/Fatec-ID-Grupo-2-2023/tgs-api-hk