fix: Fix fetching skills
parent
84208bafd3
commit
67552e4f1e
Binary file not shown.
|
@ -81,7 +81,12 @@ public class SkillsController {
|
|||
@GetMapping("/secondary-skills")
|
||||
@ResponseBody
|
||||
public Iterable<SecondarySkill> getSecondarySkills(@RequestParam Long primarySkillId) {
|
||||
return secondarySkillService.getSecondarySkillsByPrimarySkillId(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;
|
||||
}
|
||||
|
||||
@PostMapping("/save")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.maradona.backend.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import lombok.Data;
|
||||
|
||||
@Entity
|
||||
|
@ -13,10 +14,12 @@ public class EmployeeSecondarySkill {
|
|||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "employee_id", nullable = false)
|
||||
@JsonBackReference
|
||||
private Employee employee;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "secondary_skill_id", nullable = false)
|
||||
@JsonBackReference
|
||||
private SecondarySkill secondarySkill;
|
||||
|
||||
@Column(nullable = false)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.maradona.backend.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -15,48 +16,30 @@ public class PrimarySkill {
|
|||
private String description;
|
||||
|
||||
@OneToMany(mappedBy = "primarySkill", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JsonManagedReference
|
||||
private List<SecondarySkill> secondarySkills;
|
||||
|
||||
// Getters and setters
|
||||
|
||||
public Long getPsid() {
|
||||
return psid;
|
||||
}
|
||||
|
||||
public void setPsid(Long psid) {
|
||||
this.psid = psid;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
public Long getPsid() {
|
||||
return psid;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public List<SecondarySkill> getSecondarySkills() {
|
||||
return secondarySkills;
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setSecondarySkills(List<SecondarySkill> secondarySkills) {
|
||||
this.secondarySkills = secondarySkills;
|
||||
}
|
||||
|
||||
public void addSecondarySkill(SecondarySkill secondarySkill) {
|
||||
secondarySkills.add(secondarySkill);
|
||||
secondarySkill.setPrimarySkill(this);
|
||||
}
|
||||
|
||||
public void removeSecondarySkill(SecondarySkill secondarySkill) {
|
||||
secondarySkills.remove(secondarySkill);
|
||||
secondarySkill.setPrimarySkill(null);
|
||||
}
|
||||
|
||||
public void removeAllSecondarySkills() {
|
||||
for (SecondarySkill secondarySkill : secondarySkills) {
|
||||
secondarySkill.setPrimarySkill(null);
|
||||
}
|
||||
secondarySkills.clear();
|
||||
public List<SecondarySkill> getSecondarySkills() {
|
||||
return secondarySkills;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package com.maradona.backend.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -16,9 +18,11 @@ public class SecondarySkill {
|
|||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "psid", nullable = false)
|
||||
@JsonBackReference
|
||||
private PrimarySkill primarySkill;
|
||||
|
||||
@OneToMany(mappedBy = "secondarySkill", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JsonManagedReference
|
||||
private List<EmployeeSecondarySkill> employeeSecondarySkills;
|
||||
|
||||
public void setSsid(Long ssid) {
|
||||
|
|
|
@ -35,6 +35,7 @@ public class SecondarySkillService {
|
|||
for (SecondarySkill skill : skills) {
|
||||
if (skill.getPrimarySkill().getPsid().equals(primarySkillId)) {
|
||||
result.add(skill);
|
||||
System.out.println(skill.getDescription());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<title>Add Skill</title>
|
||||
<!-- never remove this metadata -->
|
||||
<div th:replace="~{_metadata :: metadata}"></div>
|
||||
<link rel="stylesheet" href="/skills.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
@ -33,11 +35,9 @@
|
|||
class="form-control"
|
||||
th:field="*{secondarySkillId}"
|
||||
>
|
||||
<option
|
||||
th:each="secondarySkill : ${secondarySkills}"
|
||||
th:value="${secondarySkill.ssid}"
|
||||
th:text="${secondarySkill.description}"
|
||||
></option>
|
||||
<option value="" disabled selected>
|
||||
Select a secondary skill
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
@ -68,16 +68,21 @@
|
|||
fetch("/skills/secondary-skills?primarySkillId=" + primarySkillId)
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
console.log("Fetch response data:", data);
|
||||
var secondarySkillSelect =
|
||||
document.getElementById("secondarySkill");
|
||||
secondarySkillSelect.innerHTML = "";
|
||||
secondarySkillSelect.innerHTML =
|
||||
'<option value="" disabled selected>Select a secondary skill</option>';
|
||||
data.forEach(function (secondarySkill) {
|
||||
var option = document.createElement("option");
|
||||
option.value = secondarySkill.ssid;
|
||||
option.text = secondarySkill.description;
|
||||
secondarySkillSelect.add(option);
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch((error) =>
|
||||
console.error("Error fetching secondary skills:", error)
|
||||
);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
Loading…
Reference in New Issue