source: src/main/java/mk/ukim/finki/wp/db/controller/SupportTicketController.java

Last change on this file was 5ea00d7, checked in by Malek Alavi <malekalavi7@…>, 8 days ago

Initial project upload

  • Property mode set to 100644
File size: 2.4 KB
Line 
1package mk.ukim.finki.wp.db.controller;
2
3import lombok.RequiredArgsConstructor;
4import mk.ukim.finki.wp.db.service.SupportTicketService;
5import org.springframework.security.core.Authentication;
6import org.springframework.security.core.GrantedAuthority;
7import org.springframework.stereotype.Controller;
8import org.springframework.ui.Model;
9import org.springframework.web.bind.annotation.GetMapping;
10import org.springframework.web.bind.annotation.PathVariable;
11import org.springframework.web.bind.annotation.PostMapping;
12import org.springframework.web.bind.annotation.RequestParam;
13
14@Controller
15@RequiredArgsConstructor
16public class SupportTicketController {
17
18 private final SupportTicketService supportTicketService;
19
20 @GetMapping("/support-ticket")
21 public String getSupportTicketPage(Model model, Authentication authentication) {
22 Object principal = authentication.getPrincipal();
23 String email = ((org.springframework.security.core.userdetails.User) principal).getUsername();
24 model.addAttribute("tickets", supportTicketService.findAll(email));
25
26 boolean loggedIn = authentication != null && authentication.isAuthenticated();
27 model.addAttribute("loggedIn", loggedIn);
28
29 String userRole = null;
30
31 if (loggedIn) {
32 userRole = authentication.getAuthorities().stream()
33 .map(GrantedAuthority::getAuthority)
34 .findFirst()
35 .orElse(null);
36 }
37
38 model.addAttribute("userRole", userRole);
39 return "support_ticket/support_ticket";
40 }
41
42 @GetMapping("/add/support-ticket")
43 public String getAddSupportTicketPage() {
44 return "support_ticket/support_ticket_form";
45 }
46
47 @PostMapping("/add/support-ticket")
48 public String addSupportTicket(@RequestParam String subject,
49 @RequestParam String description,
50 Authentication authentication) {
51 Object principal = authentication.getPrincipal();
52 String email = ((org.springframework.security.core.userdetails.User) principal).getUsername();
53 supportTicketService.addSupportTicket(email, subject, description);
54 return "redirect:/support-ticket";
55 }
56
57 @PostMapping("/resolve/support-ticket/{id}")
58 public String resolveSupportTicket(@PathVariable Integer id) {
59 supportTicketService.resolveSupportTicket(id);
60 return "redirect:/support-ticket";
61 }
62}
Note: See TracBrowser for help on using the repository browser.