api: Add skill service
parent
989a151f7a
commit
6e61318ca2
Binary file not shown.
|
@ -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";
|
||||
}
|
||||
|
||||
|
|
|
@ -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<SecondarySkill> secondarySkills;
|
||||
|
||||
public Skill(PrimarySkill primarySkill, List<SecondarySkill> secondarySkills) {
|
||||
this.primarySkill = primarySkill;
|
||||
this.secondarySkills = secondarySkills;
|
||||
}
|
||||
|
||||
public PrimarySkill getPrimarySkill() {
|
||||
return primarySkill;
|
||||
}
|
||||
|
||||
public void setPrimarySkill(PrimarySkill primarySkill) {
|
||||
this.primarySkill = primarySkill;
|
||||
}
|
||||
|
||||
public List<SecondarySkill> getSecondarySkills() {
|
||||
return secondarySkills;
|
||||
}
|
||||
|
||||
public void setSecondarySkills(List<SecondarySkill> secondarySkills) {
|
||||
this.secondarySkills = secondarySkills;
|
||||
}
|
||||
}
|
|
@ -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<Skill> getAllSkills() {
|
||||
Iterable<PrimarySkill> primarySkills = primarySkillRepository.findAll();
|
||||
Iterable<SecondarySkill> secondarySkills = secondarySkillRepository.findAll();
|
||||
List<Skill> skills = new ArrayList<>();
|
||||
|
||||
for (PrimarySkill primarySkill : primarySkills) {
|
||||
List<SecondarySkill> 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue