source: Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/EmployeeController.java@ 7aa3382

main
Last change on this file since 7aa3382 was 7aa3382, checked in by SazdovaEkaterina <sazdovaekaterina@…>, 16 months ago

add approve functionality

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[996b8ba]1package finki.paw5.web.controllers;
2
[7aa3382]3import finki.paw5.model.entities.Adopter;
4import finki.paw5.model.entities.Employee;
[996b8ba]5import finki.paw5.service.AdopterService;
[7aa3382]6import finki.paw5.service.EmployeeService;
7import jakarta.servlet.http.HttpServletRequest;
[996b8ba]8import org.springframework.stereotype.Controller;
9import org.springframework.ui.Model;
10import org.springframework.web.bind.annotation.GetMapping;
[7aa3382]11import org.springframework.web.bind.annotation.PathVariable;
12import org.springframework.web.bind.annotation.PostMapping;
[996b8ba]13import org.springframework.web.bind.annotation.RequestMapping;
14
15@Controller
16@RequestMapping("/")
17public 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}
Note: See TracBrowser for help on using the repository browser.