api: Update PrimarySkillService

pull/1/head
Lunix-420 2024-11-11 11:47:31 +01:00
parent 5258db4300
commit dcb3d0ec91
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.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);
}
}