[996b8ba] | 1 | package finki.paw5.web.controllers;
|
---|
| 2 |
|
---|
[7aa3382] | 3 | import finki.paw5.model.entities.Adopter;
|
---|
| 4 | import finki.paw5.model.entities.Employee;
|
---|
[996b8ba] | 5 | import finki.paw5.service.AdopterService;
|
---|
[7aa3382] | 6 | import finki.paw5.service.EmployeeService;
|
---|
| 7 | import jakarta.servlet.http.HttpServletRequest;
|
---|
[996b8ba] | 8 | import org.springframework.stereotype.Controller;
|
---|
| 9 | import org.springframework.ui.Model;
|
---|
| 10 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
[7aa3382] | 11 | import org.springframework.web.bind.annotation.PathVariable;
|
---|
| 12 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
[996b8ba] | 13 | import org.springframework.web.bind.annotation.RequestMapping;
|
---|
| 14 |
|
---|
| 15 | @Controller
|
---|
| 16 | @RequestMapping("/")
|
---|
| 17 | public class EmployeeController {
|
---|
[7aa3382] | 18 |
|
---|
[996b8ba] | 19 | private final AdopterService adopterService;
|
---|
[7aa3382] | 20 | private final EmployeeService employeeService;
|
---|
[996b8ba] | 21 |
|
---|
[7aa3382] | 22 | public EmployeeController(AdopterService adopterService, EmployeeService employeeService) {
|
---|
[996b8ba] | 23 | this.adopterService = adopterService;
|
---|
[7aa3382] | 24 | this.employeeService = employeeService;
|
---|
[996b8ba] | 25 | }
|
---|
| 26 |
|
---|
| 27 | @GetMapping("/approve-adopters")
|
---|
[7aa3382] | 28 | public String getApprovalPage(Model model){
|
---|
[996b8ba] | 29 | model.addAttribute("needApproval", this.adopterService.findAllThatNeedApproval());
|
---|
| 30 | return "/approve-adopters";
|
---|
| 31 | }
|
---|
[7aa3382] | 32 |
|
---|
| 33 | @PostMapping("/submit-approval-{id}")
|
---|
| 34 | public String approveAdopter(@PathVariable Integer id, HttpServletRequest request){
|
---|
| 35 |
|
---|
| 36 | Employee employeeVerificator = (Employee) request.getSession().getAttribute("user");
|
---|
| 37 |
|
---|
| 38 | Adopter adopter = this.adopterService.findById(id);
|
---|
| 39 |
|
---|
| 40 | adopter.setVerified(true);
|
---|
| 41 | adopter.setEmployeeVerificator(employeeVerificator);
|
---|
| 42 |
|
---|
| 43 | this.adopterService.save(adopter);
|
---|
| 44 |
|
---|
| 45 | return "redirect:/approve-adopters";
|
---|
| 46 | }
|
---|
[996b8ba] | 47 | }
|
---|