Simplify staff addition and update

This commit is contained in:
Simon Bruder 2023-11-23 16:43:48 +01:00 committed by Denis Natusch
parent 14dc478e41
commit a90a8cc051
No known key found for this signature in database
GPG key ID: 5E57BD8EDACFA985

View file

@ -34,13 +34,8 @@ public class StaffController {
@PostMapping("/staff/add") @PostMapping("/staff/add")
@PreAuthorize("hasRole('ADMIN')") @PreAuthorize("hasRole('ADMIN')")
public String addStaff( public String addStaff(@RequestParam String name, @RequestParam JobType job) {
@RequestParam String name, staffManagement.save(new Staff(name, job));
@RequestParam JobType job,
Model model
) {
Staff newStaff = new Staff(name, job);
staffManagement.save(newStaff);
return "redirect:/staff"; return "redirect:/staff";
} }
@ -53,11 +48,7 @@ public class StaffController {
@PostMapping("/staff/edit/{id}") @PostMapping("/staff/edit/{id}")
@PreAuthorize("hasRole('ADMIN')") @PreAuthorize("hasRole('ADMIN')")
public String updateStaff( public String updateStaff(@PathVariable("id") Staff staff, @RequestParam String name, @RequestParam JobType job) {
@PathVariable("id") Staff staff,
@RequestParam String name,
@RequestParam JobType job
) {
staff.setJob(job); staff.setJob(job);
staff.setName(name); staff.setName(name);
staffManagement.save(staff); staffManagement.save(staff);