Merge pull request 'Closes #45' (#82) from 3002833/Backend:main into restfull

Reviewed-on: Maradona/Backend#82
pull/1/head
David Hess 2024-11-11 12:03:38 +01:00
commit 1de86ba858
1 changed files with 12 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package com.maradona.backend.services;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.maradona.backend.entities.PrimarySkill; import com.maradona.backend.entities.PrimarySkill;
import com.maradona.backend.entities.SecondarySkill;
import com.maradona.backend.repositories.PrimarySkillRepository; import com.maradona.backend.repositories.PrimarySkillRepository;
import java.util.Optional; import java.util.Optional;
@ -13,6 +14,9 @@ public class PrimarySkillService {
@Autowired @Autowired
private PrimarySkillRepository primarySkillRepository; private PrimarySkillRepository primarySkillRepository;
@Autowired
private SecondarySkillService secondarySkillRepository;
public PrimarySkill savePrimarySkill(PrimarySkill primarySkill) { public PrimarySkill savePrimarySkill(PrimarySkill primarySkill) {
return primarySkillRepository.save(primarySkill); return primarySkillRepository.save(primarySkill);
} }
@ -27,10 +31,16 @@ public class PrimarySkillService {
return Optional.empty(); return Optional.empty();
} }
public void deletePrimarySkill(Long id) { public void deletePrimarySkill(Long psid) {
var primarySkills = primarySkillRepository.findAll(); 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) { for (PrimarySkill primarySkill : primarySkills) {
if (primarySkill.getPsid().equals(id)) { if (primarySkill.getPsid().equals(psid)) {
primarySkillRepository.delete(primarySkill); primarySkillRepository.delete(primarySkill);
} }
} }