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.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
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.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
@ -24,12 +25,10 @@ public class StaffController {
|
||||||
@GetMapping("/staff")
|
@GetMapping("/staff")
|
||||||
@PreAuthorize("hasRole('ADMIN')")
|
@PreAuthorize("hasRole('ADMIN')")
|
||||||
public String getStaff(Model model) {
|
public String getStaff(Model model) {
|
||||||
model.addAttribute("staff", staffManagement.findAll());
|
return getStaff(model, StaffForm.empty());
|
||||||
model.addAttribute("form", StaffForm.empty());
|
|
||||||
return "staff";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStaff(Model model, StaffForm form) {
|
public String getStaff(Model model, @Valid StaffForm form) {
|
||||||
model.addAttribute("staff", staffManagement.findAll());
|
model.addAttribute("staff", staffManagement.findAll());
|
||||||
model.addAttribute("form", form);
|
model.addAttribute("form", form);
|
||||||
return "staff";
|
return "staff";
|
||||||
|
@ -55,16 +54,21 @@ public class StaffController {
|
||||||
@GetMapping("/staff/edit/{id}")
|
@GetMapping("/staff/edit/{id}")
|
||||||
@PreAuthorize("hasRole('ADMIN')")
|
@PreAuthorize("hasRole('ADMIN')")
|
||||||
public String editEmployee(@PathVariable("id") Employee employee, Model model) {
|
public String editEmployee(@PathVariable("id") Employee employee, Model model) {
|
||||||
model.addAttribute("employee", employee);
|
return editEmployee(model, new StaffForm(employee.getName(), employee.getJob()));
|
||||||
model.addAttribute("form", new StaffForm(employee.getName(), employee.getJob()));
|
}
|
||||||
|
|
||||||
|
public String editEmployee(Model model, @Valid StaffForm form) {
|
||||||
|
model.addAttribute("form", form);
|
||||||
return "edit-staff";
|
return "edit-staff";
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/staff/edit/{id}")
|
@PostMapping("/staff/edit/{id}")
|
||||||
@PreAuthorize("hasRole('ADMIN')")
|
@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()){
|
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.setJob(form.getJob());
|
||||||
employee.setName(form.getName());
|
employee.setName(form.getName());
|
||||||
|
|
Loading…
Reference in a new issue