From 6e61318ca2523d6cb7b19f025309eb40ea78c5d6 Mon Sep 17 00:00:00 2001 From: Lunix-420 Date: Thu, 31 Oct 2024 13:32:38 +0100 Subject: [PATCH] api: Add skill service --- data/maradona/dbfile.mv.db | Bin 28672 -> 36864 bytes .../backend/controllers/PageController.java | 9 ++++ .../java/com/maradona/backend/dto/Skill.java | 31 +++++++++++++ .../backend/services/SkillService.java | 41 ++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 src/main/java/com/maradona/backend/dto/Skill.java create mode 100644 src/main/java/com/maradona/backend/services/SkillService.java diff --git a/data/maradona/dbfile.mv.db b/data/maradona/dbfile.mv.db index 818bab62034c08130ba2b3ec80ac984d96b9012d..3bef678a8397ad6ba7e282072cae76d221b2bc61 100644 GIT binary patch delta 2050 zcmbW2O>Epm6vxL-_M@9Gh=SUXifm~@n$+FSjA!k!IgnHcLQ7GqN)1$qW<2rID9LWL z*{wn^*$apZhjb7J5K!@PX~ZEchxSAzK!OVggoIQH6i!6~2_(*ZjK5uFrBwCh`PuT! zoB#j!o?E+0>$-Y$*2bE%Qsc|E9>nuYS6v%H2sM7WSzWe?wRLo2$kHk+Zi8QT>ozwL z)XR_*cG!ml;-7)O;RpP3v@maKD{j?B+8TS+U6&QCvJJZ;w_asyHgdFjt=6y+;<6g3 zL%fK!#?q>5>pErFBH9(VzP?ne+QihV?nc8lwMLEGu49OulV=JA05Z#&H-I`M+H*5` z)2&c*&-uR;abxT^wd)h{_V}qh%gW75$Z7vFKHsGhLzt6~ z$7iW~sc?f$ze=mB|Op%OvS4UTRM0ol*Ww&-`J#Gl8D;-WJ#5|`bqHrL(7 znZ|{vd_%nDjP{uCE1}|sn11|`646$cuDEk4WpoPtXJ@5K^41s03Xd+v7mDH-e|W}7 zWHEd_bjQ?coHy54mA_^~s-WIbQbfyTLnhSI7wQ!Xy*J`2e@Z-mqPOt+1>jv>>JMA& z^J~T2Smahp_n3;Zjx5ZGC8d8stQE83zmxfS>wfIT#NRz_uT{o8Wp8*!64;Ai%HB8c z-`*Sh+FK0m&GbL3fNw(* zwY?>7CN)yuALJS&T_l9aBQ9_`BraOtb@_T$Uq+6DML;DSR{yufg0))aN!)(Hl#?a`()o z=oEWYiua;Hb6T-5a;N7?axj4j@D0eQ3IKyLAusw-)!y}E_tO{q`yLuN3_$MJ+(!E+ zxSLZxZQrD?@#)Nlq+tG9L$P4 zr`I9q8@ZDkRDgoyQ}yQX%lS@o%ZLa!J;IgG#4?*Y;GrRpjUBP;91^!!IKet%V2VH3 zXs=$0d&3`LL+KF~ET>bs+7WSL;n10we#$zpnUK|SkX1fNH{y{^?AM!aNBQ5l2XAw~ zAIcuQ&7_8o9Y~U4dae`O!LRE9*%q0zV^65JLH3KUf~&=I#O0FwbtFvCt7_WuFTg;}5g delta 571 zcmZozz|`=7QQ5=FNGB;LKRFvl2WM8LS{WJ`80aKtl;&kynV3#gRu?hVNy|wsNzO%J!#T;Mh0RY&P BtS|ro 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