From dcb3d0ec916b3811812849813efadf732525137f Mon Sep 17 00:00:00 2001 From: Lunix-420 Date: Mon, 11 Nov 2024 11:47:31 +0100 Subject: [PATCH] api: Update PrimarySkillService --- .../backend/services/PrimarySkillService.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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); } }