Merge pull request 'chore: Update branch' (#3) from Maradona/Backend:main into main
Reviewed-on: #3pull/1/head
commit
9f96ee4dff
Binary file not shown.
|
@ -9,7 +9,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import com.maradona.backend.entities.SecondarySkill;
|
||||
import com.maradona.backend.entities.EmployeeSecondarySkill;
|
||||
|
@ -20,8 +19,6 @@ import com.maradona.backend.services.SecondarySkillService;
|
|||
import com.maradona.backend.dto.SkillForm;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/skills")
|
||||
|
@ -62,8 +59,8 @@ public class SkillsController {
|
|||
@GetMapping("/add")
|
||||
public String addSkill(Model model) {
|
||||
model.addAttribute("primarySkills", primarySkillService.getAllPrimarySkills());
|
||||
model.addAttribute("secondarySkills", List.of()); // Empty list initially
|
||||
model.addAttribute("skillForm", new SkillForm()); // Add a form object to the model
|
||||
model.addAttribute("secondarySkills", List.of());
|
||||
model.addAttribute("skillForm", new SkillForm());
|
||||
return "skills/skills-add";
|
||||
}
|
||||
|
||||
|
@ -90,10 +87,6 @@ public class SkillsController {
|
|||
@ResponseBody
|
||||
public Iterable<SecondarySkill> getSecondarySkills(@RequestParam Long primarySkillId) {
|
||||
var list = secondarySkillService.getSecondarySkillsByPrimarySkillId(primarySkillId);
|
||||
System.out.println("Secondary skills for primary skill " + primarySkillId + ":");
|
||||
for (SecondarySkill skill : list) {
|
||||
System.out.println(skill.getDescription());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -135,7 +128,7 @@ public class SkillsController {
|
|||
@PostMapping("/remove")
|
||||
public String remove(@RequestParam Long id) {
|
||||
var employee = employeeService.getEmployeeById(user).orElseThrow(() -> new RuntimeException("Employee not found"));
|
||||
var secondarySkill = secondarySkillService.getSecondarySkillById(id)
|
||||
secondarySkillService.getSecondarySkillById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Secondary Skill not found"));
|
||||
|
||||
employee.getSecondarySkills().removeIf(skill -> skill.getSecondarySkill().getSsid().equals(id));
|
||||
|
@ -146,26 +139,21 @@ public class SkillsController {
|
|||
|
||||
// Update skill level
|
||||
@PostMapping("/update-level")
|
||||
@ResponseBody
|
||||
public Map<String, Object> updateLevel(@RequestBody Map<String, Object> payload) {
|
||||
Long skillId = Long.valueOf((String) payload.get("skillId"));
|
||||
Integer level = Integer.valueOf((String) payload.get("level"));
|
||||
|
||||
public String updateLevel(@RequestParam Long skillId, @RequestParam Integer level) {
|
||||
var employee = employeeService.getEmployeeById(user).orElseThrow(() -> new RuntimeException("Employee not found"));
|
||||
var secondarySkill = secondarySkillService.getSecondarySkillById(skillId)
|
||||
secondarySkillService.getSecondarySkillById(skillId)
|
||||
.orElseThrow(() -> new RuntimeException("Secondary Skill not found"));
|
||||
|
||||
for (EmployeeSecondarySkill ess : employee.getSecondarySkills()) {
|
||||
if (ess.getSecondarySkill().getSsid().equals(skillId)) {
|
||||
ess.setLevel(level);
|
||||
for (EmployeeSecondarySkill skill : employee.getSecondarySkills()) {
|
||||
if (skill.getSecondarySkill().getSsid().equals(skillId)) {
|
||||
skill.setLevel(level);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
employeeService.saveEmployee(employee);
|
||||
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
return response;
|
||||
return "redirect:/skills";
|
||||
}
|
||||
|
||||
}
|
|
@ -63,7 +63,9 @@ public class SkillService {
|
|||
if (!secondarySkillList.isEmpty()) {
|
||||
skills.add(new SkillDto(primarySkill, secondarySkillList));
|
||||
}
|
||||
secondarySkillList.sort((a, b) -> a.getFirst().getDescription().compareTo(b.getFirst().getDescription()));
|
||||
}
|
||||
skills.sort((a, b) -> a.getPrimarySkill().getDescription().compareTo(b.getPrimarySkill().getDescription()));
|
||||
return skills;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue