refactor: Primary skills
parent
136e8aab3f
commit
96a79bce24
Binary file not shown.
|
@ -36,6 +36,13 @@ public class DefaultValueLoader implements CommandLineRunner {
|
|||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
|
||||
// Clear all tables
|
||||
formOfAddressRepository.deleteAll();
|
||||
employeeRepository.deleteAll();
|
||||
secondarySkillRepository.deleteAll();
|
||||
primarySkillRepository.deleteAll();
|
||||
|
||||
// Create form of addresses
|
||||
FormOfAddress formOfAddress1 = new FormOfAddress();
|
||||
formOfAddress1.setDescription("Herr");
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
@ -14,8 +15,18 @@ import com.maradona.backend.entities.SecondarySkill;
|
|||
import com.maradona.backend.services.PrimarySkillService;
|
||||
import com.maradona.backend.services.SecondarySkillService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Controller for handling primary skill data.
|
||||
*
|
||||
* List of endpoints:
|
||||
* - GET /api/primary-skill
|
||||
* - GET /api/primary-skill/all
|
||||
* - POST /api/primary-skill
|
||||
* - PUT /api/primary-skill
|
||||
* - DELETE /api/primary-skill
|
||||
*
|
||||
* @see PrimarySkill
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/primary-skill")
|
||||
public class PrimarySkillController {
|
||||
|
@ -26,6 +37,53 @@ public class PrimarySkillController {
|
|||
@Autowired
|
||||
private SecondarySkillService secondarySkillService;
|
||||
|
||||
/**
|
||||
* Returns a specific primary skill from the database.
|
||||
*
|
||||
* @param id The ID of the requested primary skill.
|
||||
* @return The primary skill with the requested ID.
|
||||
* @see PrimarySkill
|
||||
*/
|
||||
@GetMapping({ "/", "" })
|
||||
public PrimarySkill get(@RequestParam Long id) {
|
||||
return primarySkillService.getPrimarySkillById(id).orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all primary skills from the database.
|
||||
*
|
||||
* @return A list of all primary skills.
|
||||
* @see PrimarySkill
|
||||
*/
|
||||
@GetMapping("/all")
|
||||
public Iterable<PrimarySkill> getAll() {
|
||||
return primarySkillService.getAllPrimarySkills();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new primary skill to the database.
|
||||
*
|
||||
* @param primarySkill The primary skill to be added.
|
||||
* @return The added primary skill.
|
||||
* @see PrimarySkill
|
||||
*/
|
||||
@PostMapping({ "/", "" })
|
||||
public void post(@RequestBody PrimarySkill primarySkill) {
|
||||
primarySkillService.savePrimarySkill(primarySkill);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing primary skill in the database.
|
||||
*
|
||||
* @param primarySkill The primary skill to be updated.
|
||||
* @return The updated primary skill.
|
||||
* @see PrimarySkill
|
||||
*/
|
||||
@PutMapping({ "/", "" })
|
||||
public void put(@RequestBody PrimarySkill primarySkill) {
|
||||
primarySkillService.savePrimarySkill(primarySkill);
|
||||
}
|
||||
|
||||
@DeleteMapping({ "/", "" })
|
||||
public void delete(@RequestParam Long id) {
|
||||
// Find and delete all secondary skills associated with the primary skill
|
||||
|
|
|
@ -15,6 +15,15 @@ import com.maradona.backend.dto.SkillPrototype;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Controller for routing to the skills related pages.
|
||||
*
|
||||
* List of endpoints:
|
||||
* - GET /skills
|
||||
* - GET /skills/create
|
||||
* - GET /skills/add
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/skills")
|
||||
public class SkillsPage {
|
||||
|
|
|
@ -9,18 +9,13 @@ import java.util.Optional;
|
|||
|
||||
@Service
|
||||
public class SecondarySkillService {
|
||||
|
||||
@Autowired
|
||||
private SecondarySkillRepository secondarySkillRepository;
|
||||
|
||||
@Autowired
|
||||
private PrimarySkillService primarySkillService;
|
||||
|
||||
@Autowired
|
||||
private EmployeeService employeeService;
|
||||
|
||||
public SecondarySkill saveSecondarySkill(SecondarySkill secondarySkill) {
|
||||
// TODO: Use the primaries ID to find the primary skill not the description
|
||||
var primarySkillDescription = secondarySkill.getPrimarySkill().getDescription();
|
||||
var existingPrimarySkill = primarySkillService.findByDescription(primarySkillDescription);
|
||||
|
||||
|
@ -56,14 +51,4 @@ public class SecondarySkillService {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void deleteSecondarySkillFromEmployee(Long userId, Long skillId) {
|
||||
var employee = employeeService.getEmployeeById(userId)
|
||||
.orElseThrow(() -> new RuntimeException("Employee not found"));
|
||||
getSecondarySkillById(skillId)
|
||||
.orElseThrow(() -> new RuntimeException("Secondary Skill not found"));
|
||||
|
||||
employee.getSecondarySkills().removeIf(skill -> skill.getSecondarySkill().getSsid().equals(skillId));
|
||||
employeeService.saveEmployee(employee);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue