diff --git a/src/main/java/com/maradona/backend/services/PrimarySkillService.java b/src/main/java/com/maradona/backend/services/PrimarySkillService.java index d9b0ee0..169ad7a 100644 --- a/src/main/java/com/maradona/backend/services/PrimarySkillService.java +++ b/src/main/java/com/maradona/backend/services/PrimarySkillService.java @@ -3,6 +3,7 @@ package com.maradona.backend.services; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.maradona.backend.entities.PrimarySkill; +import com.maradona.backend.entities.SecondarySkill; import com.maradona.backend.repositories.PrimarySkillRepository; import java.util.Optional; @@ -13,6 +14,9 @@ public class PrimarySkillService { @Autowired private PrimarySkillRepository primarySkillRepository; + @Autowired + private SecondarySkillService secondarySkillRepository; + public PrimarySkill savePrimarySkill(PrimarySkill primarySkill) { return primarySkillRepository.save(primarySkill); } @@ -27,10 +31,16 @@ public class PrimarySkillService { return Optional.empty(); } - public void deletePrimarySkill(Long id) { + public void deletePrimarySkill(Long psid) { var primarySkills = primarySkillRepository.findAll(); + var secondarySkills = secondarySkillRepository.getAllSecondarySkills(); + for (SecondarySkill secondarySkill : secondarySkills) { + if (secondarySkill.getPrimarySkill().getPsid().equals(psid)) { + secondarySkillRepository.deleteSecondarySkill(secondarySkill.getSsid()); + } + } for (PrimarySkill primarySkill : primarySkills) { - if (primarySkill.getPsid().equals(id)) { + if (primarySkill.getPsid().equals(psid)) { primarySkillRepository.delete(primarySkill); } }