fix: Delete button user sensitivity
parent
ad4d685c51
commit
174583c06e
|
@ -38,6 +38,7 @@ public class SkillsController {
|
|||
// Hardcoded placeholder user ID for now
|
||||
Long user = Long.valueOf(1);
|
||||
|
||||
// Returns the skills overview page
|
||||
@GetMapping({ "/", "" })
|
||||
public String profile(Model model) {
|
||||
var employeeData = employeeService.getEmployeeById(user);
|
||||
|
@ -47,12 +48,14 @@ public class SkillsController {
|
|||
return "skills";
|
||||
}
|
||||
|
||||
// Returns the create-skill page
|
||||
@GetMapping("/create")
|
||||
public String createSkill(Model model) {
|
||||
model.addAttribute("secondarySkill", new SecondarySkill());
|
||||
return "create-skill";
|
||||
}
|
||||
|
||||
// Add a new skill to the user profile
|
||||
@GetMapping("/add")
|
||||
public String addSkill(Model model) {
|
||||
model.addAttribute("primarySkills", primarySkillService.getAllPrimarySkills());
|
||||
|
@ -61,6 +64,7 @@ public class SkillsController {
|
|||
return "add-skill";
|
||||
}
|
||||
|
||||
// Add a new skill to the user profile
|
||||
@PostMapping("/add")
|
||||
public String addSkill(@ModelAttribute SkillForm skillForm) {
|
||||
var employee = employeeService.getEmployeeById(user).orElseThrow(() -> new RuntimeException("Employee not found"));
|
||||
|
@ -78,6 +82,7 @@ public class SkillsController {
|
|||
return "redirect:/skills";
|
||||
}
|
||||
|
||||
// Returns a list of secondary skills for a given primary skill
|
||||
@GetMapping("/secondary-skills")
|
||||
@ResponseBody
|
||||
public Iterable<SecondarySkill> getSecondarySkills(@RequestParam Long primarySkillId) {
|
||||
|
@ -89,6 +94,7 @@ public class SkillsController {
|
|||
return list;
|
||||
}
|
||||
|
||||
// Saves a new skill to the database
|
||||
@PostMapping("/save")
|
||||
public String save(@ModelAttribute SecondarySkill secondarySkill) {
|
||||
var primarySkillDescription = secondarySkill.getPrimarySkill().getDescription();
|
||||
|
@ -104,6 +110,7 @@ public class SkillsController {
|
|||
return "redirect:/skills";
|
||||
}
|
||||
|
||||
// Deletes a primary skill and all associated secondary skills
|
||||
@PostMapping("/delete")
|
||||
public String delete(@RequestParam Long id) {
|
||||
// Find and delete all secondary skills associated with the primary skill
|
||||
|
@ -120,4 +127,19 @@ public class SkillsController {
|
|||
}
|
||||
return "redirect:/skills";
|
||||
}
|
||||
|
||||
// Removes secondary skill from user profile
|
||||
@PostMapping("/remove")
|
||||
public String remove(@RequestParam Long id) {
|
||||
var employee = employeeService.getEmployeeById(user).orElseThrow(() -> new RuntimeException("Employee not found"));
|
||||
var secondarySkills = employee.getSecondarySkills();
|
||||
for (EmployeeSecondarySkill employeeSecondarySkill : secondarySkills) {
|
||||
if (employeeSecondarySkill.getSecondarySkill().getSsid().equals(id)) {
|
||||
employee.getSecondarySkills().remove(employeeSecondarySkill);
|
||||
employeeService.saveEmployee(employee);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return "redirect:/skills";
|
||||
}
|
||||
}
|
|
@ -60,21 +60,23 @@
|
|||
>☆</span
|
||||
>
|
||||
</span>
|
||||
<form
|
||||
th:action="@{/skills/remove}"
|
||||
method="post"
|
||||
class="d-inline"
|
||||
>
|
||||
<input
|
||||
type="hidden"
|
||||
name="id"
|
||||
th:value="${pair.first.ssid}"
|
||||
/>
|
||||
<button type="submit" class="btn-delete">
|
||||
Delete
|
||||
</button>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<form
|
||||
th:action="@{/skills/delete}"
|
||||
method="post"
|
||||
class="d-inline"
|
||||
>
|
||||
<input
|
||||
type="hidden"
|
||||
name="id"
|
||||
th:value="${skillDto.primarySkill.psid}"
|
||||
/>
|
||||
<button type="submit" class="btn-delete">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue