mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Garbage
This commit is contained in:
parent
26aab5082a
commit
bd862ad9f6
|
@ -3,6 +3,7 @@ package catering.staff;
|
|||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
@ -24,12 +25,10 @@ public class StaffController {
|
|||
@GetMapping("/staff")
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public String getStaff(Model model) {
|
||||
model.addAttribute("staff", staffManagement.findAll());
|
||||
model.addAttribute("form", StaffForm.empty());
|
||||
return "staff";
|
||||
return getStaff(model, StaffForm.empty());
|
||||
}
|
||||
|
||||
public String getStaff(Model model, StaffForm form) {
|
||||
public String getStaff(Model model, @Valid StaffForm form) {
|
||||
model.addAttribute("staff", staffManagement.findAll());
|
||||
model.addAttribute("form", form);
|
||||
return "staff";
|
||||
|
@ -55,16 +54,21 @@ public class StaffController {
|
|||
@GetMapping("/staff/edit/{id}")
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public String editEmployee(@PathVariable("id") Employee employee, Model model) {
|
||||
model.addAttribute("employee", employee);
|
||||
model.addAttribute("form", new StaffForm(employee.getName(), employee.getJob()));
|
||||
return editEmployee(model, new StaffForm(employee.getName(), employee.getJob()));
|
||||
}
|
||||
|
||||
public String editEmployee(Model model, @Valid StaffForm form) {
|
||||
model.addAttribute("form", form);
|
||||
return "edit-staff";
|
||||
}
|
||||
|
||||
@PostMapping("/staff/edit/{id}")
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public String updateEmployee(@PathVariable("id") Employee employee, @Valid StaffForm form, Errors result) {
|
||||
public String updateEmployee(@PathVariable("id") Employee employee, @Valid @ModelAttribute("form") StaffForm form, Errors result, Model model) {
|
||||
if (result.hasErrors()){
|
||||
return "staff/edit/" + employee.getId();
|
||||
System.out.println(form);
|
||||
System.out.println(result);
|
||||
return editEmployee(model, form);
|
||||
}
|
||||
employee.setJob(form.getJob());
|
||||
employee.setName(form.getName());
|
||||
|
|
Loading…
Reference in a new issue