diff --git a/data/maradona/dbfile.mv.db b/data/maradona/dbfile.mv.db index 818bab6..3bef678 100644 Binary files a/data/maradona/dbfile.mv.db and b/data/maradona/dbfile.mv.db differ diff --git a/src/main/java/com/maradona/backend/controllers/PageController.java b/src/main/java/com/maradona/backend/controllers/PageController.java index 8e86045..3bbb9f4 100644 --- a/src/main/java/com/maradona/backend/controllers/PageController.java +++ b/src/main/java/com/maradona/backend/controllers/PageController.java @@ -12,6 +12,7 @@ import com.maradona.backend.services.EmployeeService; import com.maradona.backend.services.ProjectService; import com.maradona.backend.services.PrimarySkillService; import com.maradona.backend.services.SecondarySkillService; +import com.maradona.backend.services.SkillService; @Controller public class PageController { @@ -28,6 +29,9 @@ public class PageController { @Autowired private SecondarySkillService secondarySkillService; + @Autowired + private SkillService skillService; + @GetMapping("/") public String index(Model model) { var projects = projectService.getAllProjects(); @@ -40,6 +44,11 @@ public class PageController { var employeeData = employeeService.getEmployeeById(Long.valueOf(1)); System.out.println(employeeData); model.addAttribute("employee", employeeData.orElse(null)); + + var skillData = skillService.getAllSkills(); + System.out.println(skillData); + model.addAttribute("skills", skillData); + return "profile"; } diff --git a/src/main/java/com/maradona/backend/dto/Skill.java b/src/main/java/com/maradona/backend/dto/Skill.java new file mode 100644 index 0000000..999e44d --- /dev/null +++ b/src/main/java/com/maradona/backend/dto/Skill.java @@ -0,0 +1,31 @@ +package com.maradona.backend.dto; + +import com.maradona.backend.entities.PrimarySkill; +import com.maradona.backend.entities.SecondarySkill; +import java.util.List; + +public class Skill { + private PrimarySkill primarySkill; + private List secondarySkills; + + public Skill(PrimarySkill primarySkill, List secondarySkills) { + this.primarySkill = primarySkill; + this.secondarySkills = secondarySkills; + } + + public PrimarySkill getPrimarySkill() { + return primarySkill; + } + + public void setPrimarySkill(PrimarySkill primarySkill) { + this.primarySkill = primarySkill; + } + + public List getSecondarySkills() { + return secondarySkills; + } + + public void setSecondarySkills(List secondarySkills) { + this.secondarySkills = secondarySkills; + } +} \ No newline at end of file diff --git a/src/main/java/com/maradona/backend/services/SkillService.java b/src/main/java/com/maradona/backend/services/SkillService.java new file mode 100644 index 0000000..ccf18b1 --- /dev/null +++ b/src/main/java/com/maradona/backend/services/SkillService.java @@ -0,0 +1,41 @@ +package com.maradona.backend.services; + +import com.maradona.backend.dto.Skill; +import com.maradona.backend.entities.PrimarySkill; +import com.maradona.backend.entities.SecondarySkill; +import com.maradona.backend.repositories.PrimarySkillRepository; +import com.maradona.backend.repositories.SecondarySkillRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class SkillService { + + @Autowired + private PrimarySkillRepository primarySkillRepository; + + @Autowired + private SecondarySkillRepository secondarySkillRepository; + + public Iterable getAllSkills() { + Iterable primarySkills = primarySkillRepository.findAll(); + Iterable secondarySkills = secondarySkillRepository.findAll(); + List skills = new ArrayList<>(); + + for (PrimarySkill primarySkill : primarySkills) { + List secondarySkillList = new ArrayList<>(); + for (SecondarySkill secondarySkill : secondarySkills) { + var currentSecondarySkillID = secondarySkill.getPrimarySkill().getPsid(); + var currentPrimarySkillID = primarySkill.getPsid(); + if (currentSecondarySkillID.equals(currentPrimarySkillID)) { + secondarySkillList.add(secondarySkill); + } + } + skills.add(new Skill(primarySkill, secondarySkillList)); + } + return skills; + } +} \ No newline at end of file