fix: This was literally hell
parent
b22b867a6c
commit
c5c8797ba2
|
@ -13,7 +13,6 @@ import com.maradona.backend.repositories.ProjectRepository;
|
|||
import com.maradona.backend.repositories.SecondarySkillRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
|
|
@ -3,12 +3,10 @@ package com.maradona.backend.entities;
|
|||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Represents an employee.
|
||||
|
@ -48,15 +46,6 @@ public class Employee {
|
|||
@Column(length = 100)
|
||||
private String lastName;
|
||||
|
||||
/**
|
||||
* The form of address of the employee.
|
||||
*
|
||||
* This is a reference to the form of address entity.
|
||||
*/
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "form_of_address_fid")
|
||||
private FormOfAddress formOfAddress;
|
||||
|
||||
/**
|
||||
* The start time of the employee's daylie business.
|
||||
*/
|
||||
|
@ -72,18 +61,27 @@ public class Employee {
|
|||
*
|
||||
* This is a list of secondary skill entities.
|
||||
*/
|
||||
@OneToMany(mappedBy = "employee", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JsonManagedReference
|
||||
@OneToMany(mappedBy = "employee", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||
@JsonIgnore
|
||||
private List<EmployeeSecondarySkill> secondarySkills;
|
||||
|
||||
/**
|
||||
* The projects of the employee.
|
||||
* The form of address of the employee.
|
||||
*
|
||||
* This is a list of project entities.
|
||||
* This is a reference to the form of address entity.
|
||||
*/
|
||||
@ManyToMany
|
||||
@JoinTable(name = "employee_project", joinColumns = @JoinColumn(name = "employee_eid"), inverseJoinColumns = @JoinColumn(name = "project_pid"))
|
||||
@JsonBackReference
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "form_of_address_fid")
|
||||
@JsonIgnore
|
||||
private FormOfAddress formOfAddress;
|
||||
|
||||
/**
|
||||
* The projects that the employee works on.
|
||||
*
|
||||
* This is a list of references to the project entity.
|
||||
*/
|
||||
@ManyToMany(mappedBy = "employees", fetch = FetchType.LAZY)
|
||||
@JsonIgnore
|
||||
private List<Project> projects;
|
||||
|
||||
/**
|
||||
|
@ -231,12 +229,20 @@ public class Employee {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the projects of the employee.
|
||||
* Returns the projects that the employee works on.
|
||||
*
|
||||
* @param projects The projects of the employee.
|
||||
* @return The projects that the employee works on.
|
||||
*/
|
||||
public Map<SecondarySkill, Integer> getSecondarySkillLevels() {
|
||||
return secondarySkills.stream()
|
||||
.collect(Collectors.toMap(EmployeeSecondarySkill::getSecondarySkill, EmployeeSecondarySkill::getLevel));
|
||||
public List<Project> getProjects() {
|
||||
return projects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the projects that the employee works on.
|
||||
*
|
||||
* @param projects The projects that the employee works on.
|
||||
*/
|
||||
public void setProjects(List<Project> projects) {
|
||||
this.projects = projects;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package com.maradona.backend.entities;
|
|||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
/**
|
||||
* Represents an employee's secondary skill.
|
||||
|
@ -27,9 +28,9 @@ public class EmployeeSecondarySkill {
|
|||
*
|
||||
* This is a reference to the employee entity.
|
||||
*/
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "employee_eid", nullable = false)
|
||||
@JsonBackReference
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "employee_id")
|
||||
@JsonIgnore
|
||||
private Employee employee;
|
||||
|
||||
/**
|
||||
|
@ -37,8 +38,9 @@ public class EmployeeSecondarySkill {
|
|||
*
|
||||
* This is a reference to the secondary skill entity.
|
||||
*/
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "secondary_skill_id", nullable = false)
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "secondary_skill_id")
|
||||
@JsonIgnore
|
||||
private SecondarySkill secondarySkill;
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,9 @@ package com.maradona.backend.entities;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
|
||||
|
@ -37,7 +40,8 @@ public class FormOfAddress {
|
|||
*
|
||||
* This is a list of references to the employee entity.
|
||||
*/
|
||||
@OneToMany(mappedBy = "formOfAddress")
|
||||
@OneToMany(mappedBy = "formOfAddress", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||
@JsonIgnore
|
||||
private List<Employee> employees;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.maradona.backend.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
@ -37,8 +39,8 @@ public class PrimarySkill {
|
|||
*
|
||||
* This is a list of references to the secondary skill entity.
|
||||
*/
|
||||
@OneToMany(mappedBy = "primarySkill", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JsonManagedReference
|
||||
@OneToMany(mappedBy = "primarySkill", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||
@JsonIgnore
|
||||
private List<SecondarySkill> secondarySkills;
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,7 +5,7 @@ import lombok.Data;
|
|||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
/**
|
||||
* Represents a project.
|
||||
|
@ -37,8 +37,9 @@ public class Project {
|
|||
*
|
||||
* This is a list of references to the employee entity.
|
||||
*/
|
||||
@ManyToMany(mappedBy = "projects")
|
||||
@JsonManagedReference
|
||||
@ManyToMany(fetch = FetchType.LAZY)
|
||||
@JoinTable(name = "project_employee", joinColumns = @JoinColumn(name = "project_id"), inverseJoinColumns = @JoinColumn(name = "employee_id"))
|
||||
@JsonIgnore
|
||||
private List<Employee> employees;
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.maradona.backend.entities;
|
|||
|
||||
import jakarta.persistence.*;
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
@ -38,9 +39,9 @@ public class SecondarySkill {
|
|||
*
|
||||
* This is a reference to the primary skill entity.
|
||||
*/
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "psid", nullable = false)
|
||||
@JsonBackReference
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "primary_skill_id")
|
||||
@JsonIgnore
|
||||
private PrimarySkill primarySkill;
|
||||
|
||||
/**
|
||||
|
@ -48,8 +49,8 @@ public class SecondarySkill {
|
|||
*
|
||||
* This is a list of references to the employee's secondary skill entity.
|
||||
*/
|
||||
@OneToMany(mappedBy = "secondarySkill", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JsonManagedReference
|
||||
@OneToMany(mappedBy = "secondarySkill", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||
@JsonIgnore
|
||||
private List<EmployeeSecondarySkill> employeeSecondarySkills;
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,8 +3,12 @@ package com.maradona.backend.services.details;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.maradona.backend.entities.Employee;
|
||||
import com.maradona.backend.entities.EmployeeSecondarySkill;
|
||||
import com.maradona.backend.entities.SecondarySkill;
|
||||
import com.maradona.backend.repositories.EmployeeRepository;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
|
@ -55,4 +59,16 @@ public class EmployeeDetails {
|
|||
// TODO: This is a placeholder implementation
|
||||
return employeeRepository.findAll();
|
||||
}
|
||||
|
||||
// Map<SecondarySkill, Integer> secondarySkillLevels =
|
||||
// employee.getSecondarySkillLevels();
|
||||
public Map<SecondarySkill, Integer> getSecondarySkillLevels(Long eid) {
|
||||
var employee = getEmployeeByEid(eid).orElse(null);
|
||||
var employeeSecondarySkills = employee.getSecondarySkills();
|
||||
var levels = new HashMap<SecondarySkill, Integer>();
|
||||
for (EmployeeSecondarySkill employeeSecondarySkill : employeeSecondarySkills) {
|
||||
levels.put(employeeSecondarySkill.getSecondarySkill(), employeeSecondarySkill.getLevel());
|
||||
}
|
||||
return levels;
|
||||
}
|
||||
}
|
|
@ -78,7 +78,7 @@ public class SkillService {
|
|||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
Map<SecondarySkill, Integer> secondarySkillLevels = employee.getSecondarySkillLevels();
|
||||
Map<SecondarySkill, Integer> secondarySkillLevels = employeeDetails.getSecondarySkillLevels(eid);
|
||||
List<SkillList> skills = new ArrayList<>();
|
||||
|
||||
for (PrimarySkill primarySkill : primarySkillDetails.getAllPrimarySkills()) {
|
||||
|
|
Loading…
Reference in New Issue