Merge pull request 'refactor: Rename all IDs' (#81) from 3002833/Backend:main into restfull

Reviewed-on: Maradona/Backend#81
pull/1/head
David Hess 2024-11-11 11:39:45 +01:00
commit a08d3221ac
18 changed files with 192 additions and 137 deletions

View File

@ -21,6 +21,7 @@ import com.maradona.backend.services.EmployeeService;
*
* Endpoints:
* - GET /api/employee
* - GET /api/employee/{eid}
* - GET /api/employee/all
* - GET /api/employee/from-skill
* - GET /api/employee/skill/all
@ -40,15 +41,29 @@ public class EmployeeController {
Long user = Long.valueOf(1);
/**
* Returns a specific employee from the database.
* Returns the employee profile of the currently logged in user.
*
* @param id The ID of the requested employee.
* @return The employee with the requested ID.
* @return The employee profile of the currently logged in user.
* @see com.maradona.backend.entities.Employee
*/
@GetMapping({ "/", "" })
public ResponseEntity<Employee> get(@RequestParam Long id) {
var employee = employeeService.getEmployeeById(id);
public ResponseEntity<Employee> get() {
var employee = employeeService.getEmployeeByEid(user);
return employee
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
/**
* Returns a specific employee from the database.
*
* @param eid The ID of the requested employee.
* @return The employee with the requested ID.
* @see com.maradona.backend.entities.Employee
*/
@GetMapping("/{eid}")
public ResponseEntity<Employee> get(@RequestParam Long eid) {
var employee = employeeService.getEmployeeByEid(eid);
return employee
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
@ -68,15 +83,15 @@ public class EmployeeController {
/**
* Returns a list of employees for a given secondary skill and level.
*
* @param skillId ID of the secondary skill
* @param ssid ID of the secondary skill
* @param level Level of the secondary skill
* @return list of employees
* @see com.maradona.backend.entities.Employee
* @see com.maradona.backend.entities.SecondarySkill
*/
@GetMapping("/from-skill")
public ResponseEntity<Iterable<Employee>> getFromSkill(@RequestParam Long skillId, @RequestParam Integer level) {
return ResponseEntity.ok(employeeService.getEmployeesBySecondarySkill(skillId, level));
public ResponseEntity<Iterable<Employee>> getFromSkill(@RequestParam Long ssid, @RequestParam Integer level) {
return ResponseEntity.ok(employeeService.getEmployeesBySecondarySkill(ssid, level));
}
/**
@ -97,7 +112,7 @@ public class EmployeeController {
/**
* Updates the level of a secondary skill in the user profile.
*
* @param skillId ID of the secondary skill
* @param ssid ID of the secondary skill
* @param level Level of the secondary skill
* @return HTTP status indicating the outcome of the operation
* @see com.maradona.backend.entities.Employee
@ -105,22 +120,22 @@ public class EmployeeController {
* @see com.maradona.backend.entities.EmployeeSecondarySkill
*/
@PutMapping("/skill/level")
public ResponseEntity<Void> putSkillLevel(@RequestParam Long skillId, @RequestParam Integer level) {
employeeService.updateSecondarySkillLevel(user, skillId, level);
public ResponseEntity<Void> putSkillLevel(@RequestParam Long ssid, @RequestParam Integer level) {
employeeService.updateSecondarySkillLevel(user, ssid, level);
return ResponseEntity.ok().build();
}
/**
* Removes a secondary skill from the user profile.
*
* @param id The ID of the secondary skill to be removed
* @param ssid The ID of the secondary skill to be removed
* @return HTTP status indicating the outcome of the operation
* @see com.maradona.backend.entities.Employee
* @see com.maradona.backend.entities.SecondarySkill
*/
@DeleteMapping("/skill")
public ResponseEntity<Void> delete(@RequestParam Long id) {
employeeService.deleteSecondarySkillFromEmployee(user, id);
public ResponseEntity<Void> delete(@RequestParam Long ssid) {
employeeService.deleteSecondarySkillFromEmployee(user, ssid);
return ResponseEntity.noContent().build();
}
}

View File

@ -37,13 +37,13 @@ class FormOfAdressController {
/**
* Returns the form of address with the given ID.
*
* @param id The ID of the form of address to return.
* @param fid The ID of the form of address to return.
* @return The description of the form of address with the given ID.
* @see com.maradona.backend.entities.FormOfAddress
*/
@GetMapping({ "/", "" })
public ResponseEntity<FormOfAddress> getFormOfAdress(@RequestParam Long id) {
return formOfAdressService.getFormOfAddressById(id)
public ResponseEntity<FormOfAddress> getFormOfAdress(@RequestParam Long fid) {
return formOfAdressService.getFormOfAddressByFid(fid)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@ -78,14 +78,14 @@ class FormOfAdressController {
/**
* Updates the description of a form of address.
*
* @param id The ID of the form of address to update.
* @param fid The ID of the form of address to update.
* @param description The new description of the form of address.
* @return The updated form of address.
* @see com.maradona.backend.entities.FormOfAddress
*/
@PutMapping({ "/", "" })
public ResponseEntity<Void> updateFormOfAdress(@RequestParam Long id, @RequestBody String description) {
var formOfAddress = formOfAdressService.getFormOfAddressById(id).orElse(null);
public ResponseEntity<Void> updateFormOfAdress(@RequestParam Long fid, @RequestBody String description) {
var formOfAddress = formOfAdressService.getFormOfAddressByFid(fid).orElse(null);
if (formOfAddress == null) {
return ResponseEntity.notFound().build();
}
@ -97,17 +97,17 @@ class FormOfAdressController {
/**
* Deletes a form of address.
*
* @param id The ID of the form of address to delete.
* @param fid The ID of the form of address to delete.
* @return The deleted form of address.
* @see com.maradona.backend.entities.FormOfAddress
*/
@DeleteMapping({ "/", "" })
public ResponseEntity<Void> deleteFormOfAdress(@RequestParam Long id) {
var formOfAddress = formOfAdressService.getFormOfAddressById(id).orElse(null);
public ResponseEntity<Void> deleteFormOfAdress(@RequestParam Long fid) {
var formOfAddress = formOfAdressService.getFormOfAddressByFid(fid).orElse(null);
if (formOfAddress == null) {
return ResponseEntity.notFound().build();
}
formOfAdressService.deleteFormOfAddress(id);
formOfAdressService.deleteFormOfAddress(fid);
return ResponseEntity.ok().build();
}
}

View File

@ -42,13 +42,13 @@ public class PrimarySkillController {
/**
* Returns a specific primary skill from the database.
*
* @param id The ID of the requested primary skill.
* @param pid The ID of the requested primary skill.
* @return The primary skill with the requested ID.
* @see com.maradona.backend.entities.PrimarySkill
*/
@GetMapping({ "/", "" })
public ResponseEntity<PrimarySkill> get(@RequestParam Long id) {
return primarySkillService.getPrimarySkillById(id)
public ResponseEntity<PrimarySkill> get(@RequestParam Long pid) {
return primarySkillService.getPrimarySkillByPsid(pid)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@ -93,21 +93,21 @@ public class PrimarySkillController {
/**
* Deletes a primary skill from the database.
*
* @param id The ID of the primary skill to be deleted
* @param pid The ID of the primary skill to be deleted
* @return HTTP status indicating the outcome of the operation
* @see com.maradona.backend.entities.PrimarySkill
*/
@DeleteMapping({ "/", "" })
public ResponseEntity<Void> delete(@RequestParam Long id) {
var primarySkill = primarySkillService.getPrimarySkillById(id);
public ResponseEntity<Void> delete(@RequestParam Long pid) {
var primarySkill = primarySkillService.getPrimarySkillByPsid(pid);
if (primarySkill.isPresent()) {
var secondarySkills = secondarySkillService.getAllSecondarySkills();
for (SecondarySkill secondarySkill : secondarySkills) {
if (secondarySkill.getPrimarySkill().getPsid().equals(id)) {
if (secondarySkill.getPrimarySkill().getPsid().equals(pid)) {
secondarySkillService.deleteSecondarySkill(secondarySkill.getSsid());
}
}
primarySkillService.deletePrimarySkill(id);
primarySkillService.deletePrimarySkill(pid);
return ResponseEntity.noContent().build();
} else {
return ResponseEntity.notFound().build();

View File

@ -41,13 +41,13 @@ public class ProjectController {
/**
* Returns a specific project from the database.
*
* @param id The ID of the requested project.
* @param psid The ID of the requested project.
* @return The project with the requested ID.
* @see com.maradona.backend.entities.Project
*/
@GetMapping({ "/", "" })
public ResponseEntity<Project> get(@RequestParam Long id) {
Optional<Project> project = projectService.getProjectById(id);
public ResponseEntity<Project> get(@RequestParam Long psid) {
Optional<Project> project = projectService.getProjectByPid(psid);
return project.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}
@ -63,15 +63,15 @@ public class ProjectController {
}
/**
* Returns a list of projects for a given user.
* Returns a list of projects for a given employee.
*
* @param userId ID of the user
* @param eid ID of the employee
* @return list of projects
* @see com.maradona.backend.entities.Project
*/
@GetMapping("/from-user")
public ResponseEntity<Iterable<Project>> getFromUser(@RequestParam Long userId) {
return ResponseEntity.ok(projectService.getProjectsByUserId(userId));
@GetMapping("/from-employee")
public ResponseEntity<Iterable<Project>> getFromUser(@RequestParam Long eid) {
return ResponseEntity.ok(projectService.getProjectsByEid(eid));
}
/**
@ -103,13 +103,13 @@ public class ProjectController {
/**
* Deletes a project from the database.
*
* @param id The ID of the project to be deleted
* @param pid The ID of the project to be deleted
* @return HTTP status indicating the outcome of the operation
* @see com.maradona.backend.entities.Project
*/
@DeleteMapping({ "/", "" })
public ResponseEntity<Void> delete(@RequestParam Long id) {
projectService.deleteProject(id);
public ResponseEntity<Void> delete(@RequestParam Long pid) {
projectService.deleteProject(pid);
return ResponseEntity.noContent().build();
}
}

View File

@ -40,13 +40,13 @@ public class SecondarySkillController {
/**
* Returns a specific secondary skill from the database.
*
* @param id The ID of the requested secondary skill.
* @param ssid The ID of the requested secondary skill.
* @return The secondary skill with the requested ID.
* @see com.maradona.backend.entities.SecondarySkill
*/
@GetMapping({ "/", "" })
public ResponseEntity<SecondarySkill> get(@RequestParam Long id) {
Optional<SecondarySkill> secondarySkill = secondarySkillService.getSecondarySkillById(id);
public ResponseEntity<SecondarySkill> get(@RequestParam Long ssid) {
Optional<SecondarySkill> secondarySkill = secondarySkillService.getSecondarySkillBySsid(ssid);
return secondarySkill.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}
@ -64,14 +64,14 @@ public class SecondarySkillController {
/**
* Returns a list of secondary skills for a given primary skill.
*
* @param primarySkillId ID of the primary skill
* @param psid ID of the primary skill
* @return list of secondary skills
* @see com.maradona.backend.entities.SecondarySkill
* @see com.maradona.backend.entities.PrimarySkill
*/
@GetMapping("/from-primary-skill")
public ResponseEntity<Iterable<SecondarySkill>> getSecondarySkills(@RequestParam Long primarySkillId) {
return ResponseEntity.ok(secondarySkillService.getSecondarySkillsByPrimarySkillId(primarySkillId));
public ResponseEntity<Iterable<SecondarySkill>> getSecondarySkills(@RequestParam Long psid) {
return ResponseEntity.ok(secondarySkillService.getSecondarySkillsByPrimarySkillId(psid));
}
/**
@ -103,13 +103,13 @@ public class SecondarySkillController {
/**
* Deletes a secondary skill from the database.
*
* @param id The ID of the secondary skill to be deleted
* @param ssid The ID of the secondary skill to be deleted
* @return HTTP status indicating the outcome of the operation
* @see com.maradona.backend.entities.SecondarySkill
*/
@DeleteMapping({ "/", "" })
public ResponseEntity<Void> delete(@RequestParam Long id) {
secondarySkillService.deleteSecondarySkill(id);
public ResponseEntity<Void> delete(@RequestParam Long ssid) {
secondarySkillService.deleteSecondarySkill(ssid);
return ResponseEntity.noContent().build();
}
}

View File

@ -52,7 +52,7 @@ public class SkillsPage {
*/
@GetMapping({ "/", "" })
public String profile(Model model) {
model.addAttribute("employee", employeeService.getEmployeeById(user).orElse(null));
model.addAttribute("employee", employeeService.getEmployeeByEid(user).orElse(null));
model.addAttribute("skills", skillService.getUserSkills(user));
return "/pages/skills/overview";
}

View File

@ -1,24 +1,24 @@
package com.maradona.backend.dto;
public class SkillPrototype {
private Long primarySkillId;
private Long secondarySkillId;
private Long psid;
private Long ssid;
private Integer level;
public Long getPrimarySkillId() {
return primarySkillId;
public Long getPsid() {
return psid;
}
public void setPrimarySkillId(Long primarySkillId) {
this.primarySkillId = primarySkillId;
public void setPsid(Long psid) {
this.psid = psid;
}
public Long getSecondarySkillId() {
return secondarySkillId;
public Long getSsid() {
return ssid;
}
public void setSecondarySkillId(Long secondarySkillId) {
this.secondarySkillId = secondarySkillId;
public void setSsid(Long ssid) {
this.ssid = ssid;
}
public Integer getLevel() {

View File

@ -24,7 +24,7 @@ public class Employee {
private String lastName;
@ManyToOne
@JoinColumn(name = "AID")
@JoinColumn(name = "FID")
private FormOfAddress formOfAddress;
private LocalTime dStart;

View File

@ -9,10 +9,10 @@ import com.fasterxml.jackson.annotation.JsonBackReference;
public class EmployeeSecondarySkill {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Long essid;
@ManyToOne
@JoinColumn(name = "employee_id", nullable = false)
@JoinColumn(name = "employee_eid", nullable = false)
@JsonBackReference
private Employee employee;
@ -23,12 +23,12 @@ public class EmployeeSecondarySkill {
@Column(nullable = false)
private Integer level;
public void setId(Long id) {
this.id = id;
public void setEssid(Long essid) {
this.essid = essid;
}
public Long getId() {
return id;
public Long getEssid() {
return essid;
}
public void setEmployee(Employee employee) {

View File

@ -9,17 +9,17 @@ public class FormOfAddress {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Long fid;
@Column(nullable = false, length = 50)
private String description;
public void setId(Long id) {
this.id = id;
public void setFid(Long fid) {
this.fid = fid;
}
public Long getId() {
return id;
public Long getFid() {
return fid;
}
public void setDescription(String description) {

View File

@ -10,7 +10,7 @@ public class Project {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Long pid;
@Column(nullable = false, length = 255)
private String name;
@ -23,6 +23,14 @@ public class Project {
@Column(columnDefinition = "TEXT")
private String description;
public void setPid(Long pid) {
this.pid = pid;
}
public Long getPid() {
return pid;
}
public void setName(String name) {
this.name = name;
}

View File

@ -2,8 +2,6 @@ package com.maradona.backend.repositories;
import org.springframework.data.repository.CrudRepository;
import com.maradona.backend.entities.EmployeeSecondarySkill;
import java.util.List;
public interface EmployeeSecondarySkillRepository extends CrudRepository<EmployeeSecondarySkill, Long> {
List<EmployeeSecondarySkill> findByEmployeeId(Long employeeId);
}

View File

@ -21,19 +21,19 @@ public class EmployeeService {
return employeeRepository.save(employee);
}
public Optional<Employee> getEmployeeById(Long id) {
public Optional<Employee> getEmployeeByEid(Long eid) {
var employees = employeeRepository.findAll();
for (Employee employee : employees) {
if (employee.getEid().equals(id)) {
if (employee.getEid().equals(eid)) {
return Optional.of(employee);
}
}
return Optional.empty();
}
public void deleteEmployee(Long id) {
public void deleteEmployee(Long eid) {
for (Employee employee : employeeRepository.findAll()) {
if (employee.getEid().equals(id)) {
if (employee.getEid().equals(eid)) {
employeeRepository.delete(employee);
return;
}
@ -44,13 +44,13 @@ public class EmployeeService {
return employeeRepository.findAll();
}
public void addSecondarySkillToEmployee(Long userId, SkillPrototype skillPrototype) {
var employee = getEmployeeById(userId).orElseThrow(() -> new RuntimeException("Employee not found"));
var secondarySkill = secondarySkillService.getSecondarySkillById(skillPrototype.getSecondarySkillId())
public void addSecondarySkillToEmployee(Long eid, SkillPrototype skillPrototype) {
var employee = getEmployeeByEid(eid).orElseThrow(() -> new RuntimeException("Employee not found"));
var secondarySkill = secondarySkillService.getSecondarySkillBySsid(skillPrototype.getSsid())
.orElseThrow(() -> new RuntimeException("Secondary Skill not found"));
for (EmployeeSecondarySkill skill : employee.getSecondarySkills()) {
if (skill.getSecondarySkill().getSsid().equals(skillPrototype.getSecondarySkillId())) {
if (skill.getSecondarySkill().getSsid().equals(skillPrototype.getSsid())) {
return;
}
}
@ -63,13 +63,14 @@ public class EmployeeService {
saveEmployee(employee);
}
public void updateSecondarySkillLevel(Long userId, Long skillId, Integer level) {
var employee = getEmployeeById(userId).orElseThrow(() -> new RuntimeException("Employee not found"));
secondarySkillService.getSecondarySkillById(skillId)
public void updateSecondarySkillLevel(Long eid, Long ssid, Integer level) {
var employee = getEmployeeByEid(eid).orElseThrow(() -> new RuntimeException("Employee not found"));
secondarySkillService.getSecondarySkillBySsid(
ssid)
.orElseThrow(() -> new RuntimeException("Secondary Skill not found"));
for (EmployeeSecondarySkill skill : employee.getSecondarySkills()) {
if (skill.getSecondarySkill().getSsid().equals(skillId)) {
if (skill.getSecondarySkill().getSsid().equals(ssid)) {
skill.setLevel(level);
break;
}
@ -78,18 +79,19 @@ public class EmployeeService {
saveEmployee(employee);
}
public void deleteSecondarySkillFromEmployee(Long userId, Long skillId) {
var employee = getEmployeeById(userId).orElseThrow(() -> new RuntimeException("Employee not found"));
secondarySkillService.getSecondarySkillById(skillId)
public void deleteSecondarySkillFromEmployee(Long eid, Long ssid) {
var employee = getEmployeeByEid(eid).orElseThrow(() -> new RuntimeException("Employee not found"));
secondarySkillService.getSecondarySkillBySsid(
ssid)
.orElseThrow(() -> new RuntimeException("Secondary Skill not found"));
employee.getSecondarySkills().removeIf(skill -> skill.getSecondarySkill().getSsid().equals(skillId));
employee.getSecondarySkills().removeIf(skill -> skill.getSecondarySkill().getSsid().equals(ssid));
saveEmployee(employee);
}
public Iterable<Employee> getEmployeesBySecondarySkill(Long skillId, Integer level) {
public Iterable<Employee> getEmployeesBySecondarySkill(Long ssid, Integer level) {
// Implement logic to fetch employees by secondary skill and level
// This is a placeholder implementation
// TODO: This is a placeholder implementation
return employeeRepository.findAll();
}
}

View File

@ -17,25 +17,32 @@ public class FormOfAddressService {
return formOfAddressRepository.save(formOfAddress);
}
public Optional<FormOfAddress> getFormOfAddressById(Long id) {
return formOfAddressRepository.findById(id);
public Optional<FormOfAddress> getFormOfAddressByFid(Long fid) {
var formOfAddresses = formOfAddressRepository.findAll();
for (FormOfAddress formOfAddress : formOfAddresses) {
if (formOfAddress.getFid().equals(fid)) {
return Optional.of(formOfAddress);
}
}
return Optional.empty();
}
public void deleteFormOfAddress(Long id) {
formOfAddressRepository.deleteById(id);
public void deleteFormOfAddress(Long fid) {
for (FormOfAddress formOfAddress : formOfAddressRepository.findAll()) {
if (formOfAddress.getFid().equals(fid)) {
formOfAddressRepository.delete(formOfAddress);
return;
}
}
}
public Iterable<FormOfAddress> getAllFormOfAddresses() {
return formOfAddressRepository.findAll();
}
public Long updateFormOfAddress(Long id, String description) {
var formOfAddress = formOfAddressRepository.findById(id).orElse(null);
if (formOfAddress != null) {
public void updateFormOfAddress(Long fid, String description) {
var formOfAddress = getFormOfAddressByFid(fid).orElseThrow(() -> new RuntimeException("Form of Address not found"));
formOfAddress.setDescription(description);
formOfAddressRepository.save(formOfAddress);
return id;
}
return null;
saveFormOfAddress(formOfAddress);
}
}

View File

@ -17,12 +17,23 @@ public class PrimarySkillService {
return primarySkillRepository.save(primarySkill);
}
public Optional<PrimarySkill> getPrimarySkillById(Long id) {
return primarySkillRepository.findById(id);
public Optional<PrimarySkill> getPrimarySkillByPsid(Long psid) {
var primarySkills = primarySkillRepository.findAll();
for (PrimarySkill primarySkill : primarySkills) {
if (primarySkill.getPsid().equals(psid)) {
return Optional.of(primarySkill);
}
}
return Optional.empty();
}
public void deletePrimarySkill(Long id) {
primarySkillRepository.deleteById(id);
var primarySkills = primarySkillRepository.findAll();
for (PrimarySkill primarySkill : primarySkills) {
if (primarySkill.getPsid().equals(id)) {
primarySkillRepository.delete(primarySkill);
}
}
}
public Iterable<PrimarySkill> getAllPrimarySkills() {

View File

@ -17,19 +17,30 @@ public class ProjectService {
return projectRepository.save(project);
}
public Optional<Project> getProjectById(Long id) {
return projectRepository.findById(id);
public Optional<Project> getProjectByPid(Long pid) {
var projects = projectRepository.findAll();
for (Project project : projects) {
if (project.getPid().equals(pid)) {
return Optional.of(project);
}
}
return Optional.empty();
}
public void deleteProject(Long id) {
projectRepository.deleteById(id);
public void deleteProject(Long pid) {
var projects = projectRepository.findAll();
for (Project project : projects) {
if (project.getPid().equals(pid)) {
projectRepository.delete(project);
}
}
}
public Iterable<Project> getAllProjects() {
return projectRepository.findAll();
}
public Iterable<Project> getProjectsByUserId(Long userId) {
public Iterable<Project> getProjectsByEid(Long eid) {
// TODO: Actually filter by user
return projectRepository.findAll();
}

View File

@ -28,23 +28,29 @@ public class SecondarySkillService {
return secondarySkillRepository.save(secondarySkill);
}
public Optional<SecondarySkill> getSecondarySkillById(Long id) {
return secondarySkillRepository.findById(id);
public Optional<SecondarySkill> getSecondarySkillBySsid(Long ssid) {
var secondarySkills = secondarySkillRepository.findAll();
for (SecondarySkill secondarySkill : secondarySkills) {
if (secondarySkill.getSsid().equals(ssid)) {
return Optional.of(secondarySkill);
}
}
return Optional.empty();
}
public void deleteSecondarySkill(Long id) {
secondarySkillRepository.deleteById(id);
public void deleteSecondarySkill(Long ssid) {
secondarySkillRepository.deleteById(ssid);
}
public Iterable<SecondarySkill> getAllSecondarySkills() {
return secondarySkillRepository.findAll();
}
public Iterable<SecondarySkill> getSecondarySkillsByPrimarySkillId(Long primarySkillId) {
public Iterable<SecondarySkill> getSecondarySkillsByPrimarySkillId(Long psid) {
var skills = secondarySkillRepository.findAll();
var result = new java.util.ArrayList<SecondarySkill>();
for (SecondarySkill skill : skills) {
if (skill.getPrimarySkill().getPsid().equals(primarySkillId)) {
if (skill.getPrimarySkill().getPsid().equals(psid)) {
result.add(skill);
System.out.println(skill.getDescription());
}

View File

@ -4,9 +4,6 @@ import com.maradona.backend.dto.SkillList;
import com.maradona.backend.entities.Employee;
import com.maradona.backend.entities.PrimarySkill;
import com.maradona.backend.entities.SecondarySkill;
import com.maradona.backend.repositories.EmployeeRepository;
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 org.springframework.data.util.Pair;
@ -19,24 +16,24 @@ import java.util.Map;
public class SkillService {
@Autowired
private PrimarySkillRepository primarySkillRepository;
private PrimarySkillService primarySkillService;
@Autowired
private SecondarySkillRepository secondarySkillRepository;
private SecondarySkillService secondarySkillService;
@Autowired
private EmployeeRepository employeeRepository;
private EmployeeService employeeService;
public Iterable<SkillList> getAllSkills() {
Iterable<PrimarySkill> primarySkills = primarySkillRepository.findAll();
Iterable<SecondarySkill> secondarySkills = secondarySkillRepository.findAll();
Iterable<PrimarySkill> primarySkills = primarySkillService.getAllPrimarySkills();
Iterable<SecondarySkill> secondarySkills = secondarySkillService.getAllSecondarySkills();
List<SkillList> skills = new ArrayList<>();
for (PrimarySkill primarySkill : primarySkills) {
List<Pair<SecondarySkill, Integer>> secondarySkillList = new ArrayList<>();
for (SecondarySkill secondarySkill : secondarySkills) {
if (secondarySkill.getPrimarySkill().getPsid().equals(primarySkill.getPsid())) {
secondarySkillList.add(Pair.of(secondarySkill, 3)); // Placeholder level
secondarySkillList.add(Pair.of(secondarySkill, 3));
}
}
skills.add(new SkillList(primarySkill, secondarySkillList));
@ -44,11 +41,11 @@ public class SkillService {
return skills;
}
public Iterable<SkillList> getUserSkills(Long userId) {
if (userId == null) {
public Iterable<SkillList> getUserSkills(Long eid) {
if (eid == null) {
return new ArrayList<>();
}
Employee employee = employeeRepository.findById(userId).orElse(null);
Employee employee = employeeService.getEmployeeByEid(eid).orElse(null);
if (employee == null) {
return new ArrayList<>();
}
@ -56,7 +53,7 @@ public class SkillService {
Map<SecondarySkill, Integer> secondarySkillLevels = employee.getSecondarySkillLevels();
List<SkillList> skills = new ArrayList<>();
for (PrimarySkill primarySkill : primarySkillRepository.findAll()) {
for (PrimarySkill primarySkill : primarySkillService.getAllPrimarySkills()) {
List<Pair<SecondarySkill, Integer>> secondarySkillList = new ArrayList<>();
for (Map.Entry<SecondarySkill, Integer> entry : secondarySkillLevels.entrySet()) {
if (entry.getKey().getPrimarySkill().getPsid().equals(primarySkill.getPsid())) {