1 | package finki.paw5.web.controllers;
|
---|
2 |
|
---|
3 | import finki.paw5.model.entities.Adopter;
|
---|
4 | import finki.paw5.model.entities.Employee;
|
---|
5 | import finki.paw5.service.AdopterService;
|
---|
6 | import finki.paw5.service.EmployeeService;
|
---|
7 | import jakarta.servlet.http.HttpServletRequest;
|
---|
8 | import org.springframework.stereotype.Controller;
|
---|
9 | import org.springframework.ui.Model;
|
---|
10 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
11 | import org.springframework.web.bind.annotation.PathVariable;
|
---|
12 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
13 | import org.springframework.web.bind.annotation.RequestMapping;
|
---|
14 |
|
---|
15 | @Controller
|
---|
16 | @RequestMapping("/")
|
---|
17 | public class EmployeeController {
|
---|
18 |
|
---|
19 | private final AdopterService adopterService;
|
---|
20 | private final EmployeeService employeeService;
|
---|
21 |
|
---|
22 | public EmployeeController(AdopterService adopterService, EmployeeService employeeService) {
|
---|
23 | this.adopterService = adopterService;
|
---|
24 | this.employeeService = employeeService;
|
---|
25 | }
|
---|
26 |
|
---|
27 | @GetMapping("/approve-adopters")
|
---|
28 | public String getApprovalPage(Model model){
|
---|
29 | model.addAttribute("needApproval", this.adopterService.findAllThatNeedApproval());
|
---|
30 | return "/approve-adopters";
|
---|
31 | }
|
---|
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 | }
|
---|
47 | }
|
---|