I have 2 methods get
I use springboot and the first one brings all active people boolean active
and the second one to the contacts that the person has, but I need you to bring me those contactos
according to whether they are active or not , thank you
@GetMapping("/personemergencycontacts")
public List<PersonEmergencyContact> getAllActive() {
List<PersonEmergencyContact> lista = service.findAllByActive();
return lista;
}
@GetMapping("/personemergencycontacts/person/{id}")
public List<PersonEmergencyContact> getPersonEmergencyContactByPersonId(@PathVariable(value = "id") Long PersonEmergencyContactId) {
List<PersonEmergencyContact> lista = service.findByPersonId(PersonEmergencyContactId);
return lista;
}
Repository
public interface PersonEmergencyContactRepository extends CrudRepository<PersonEmergencyContact, Long> {
@Query("SELECT p FROM PersonEmergencyContact p WHERE p.active = 1")
List<PersonEmergencyContact> findAllByActive();
List<PersonEmergencyContact> findByPersonId(Long id);
}
Service, only the relevant lists in this case
@Override
public List<PersonEmergencyContact> findAll() {
return super.findAll();
}
public List<PersonEmergencyContact> findAllByActive() { return dao.findAllByActive(); }
public List<PersonEmergencyContact> findByPersonId(Long PersonEmergencyContactId) { return dao.findByPersonId(PersonEmergencyContactId); }
public void softDelete(Long Id) {
PersonEmergencyContact personemergencycontact = this.findById(Id);
personemergencycontact.setDeleted_at(toISO8601UTC(new Date()));
personemergencycontact.setActive(false);
this.update(personemergencycontact);
}
}
and the soft delete that changes the field active
(default 1) to 0