source: bus-n-go-do-5ta-faza/src/main/java/mk/ukim/finki/busngo/web/BiletController.java

Last change on this file was baf4cc4, checked in by ppaunovski <paunovskipavel@…>, 3 months ago

split group project and individual project into two separate folders

  • Property mode set to 100644
File size: 2.9 KB
Line 
1package mk.ukim.finki.busngo.web;
2
3import mk.ukim.finki.busngo.model.entities.Patnik;
4import mk.ukim.finki.busngo.model.enums.BILET_STATUS;
5import mk.ukim.finki.busngo.model.exceptions.InvalidPatnikIdException;
6import mk.ukim.finki.busngo.service.AuthService;
7import mk.ukim.finki.busngo.service.BiletService;
8import mk.ukim.finki.busngo.service.PatnikService;
9import mk.ukim.finki.busngo.service.TipBiletService;
10import org.springframework.security.core.Authentication;
11import org.springframework.stereotype.Controller;
12import org.springframework.ui.Model;
13import org.springframework.web.bind.annotation.GetMapping;
14import org.springframework.web.bind.annotation.PostMapping;
15import org.springframework.web.bind.annotation.RequestMapping;
16import org.springframework.web.bind.annotation.RequestParam;
17
18import java.time.LocalDateTime;
19
20@Controller
21@RequestMapping("/bilet")
22public class BiletController {
23 private final BiletService biletService;
24 private final TipBiletService tipBiletService;
25 private final AuthService authService;
26 private final PatnikService patnikService;
27
28 public BiletController(BiletService biletService, TipBiletService tipBiletService, AuthService authService, PatnikService patnikService) {
29 this.biletService = biletService;
30 this.tipBiletService = tipBiletService;
31 this.authService = authService;
32 this.patnikService = patnikService;
33 }
34
35 @GetMapping()
36 public String getAllBileti(@RequestParam(required = false) Long id,
37 @RequestParam(required = false) BILET_STATUS status,
38 Model model,
39 Authentication authentication){
40 model.addAttribute("bodyContent", "listBileti");
41 Patnik patnik = null;
42 try{
43 patnik = patnikService.loadUserByEmail(authentication.getName());
44 model.addAttribute("bileti", biletService.findAllByPatnikEmail(authentication.getName()));
45 }
46 catch (InvalidPatnikIdException e){
47 model.addAttribute("bodyContent", "listBileti");
48 model.addAttribute("hasError", true);
49 model.addAttribute("error", e.getMessage());
50 return "master-template";
51 }
52
53 return "master-template";
54 }
55
56 @GetMapping("/kupi")
57 public String getKupiPage(Model model){
58 model.addAttribute("bodyContent", "kupiBilet");
59 model.addAttribute("tipbileti", tipBiletService.listAll());
60 return "master-template";
61 }
62
63 @PostMapping("/kupi")
64 public String kupiBilet(@RequestParam Long tipbilet, Authentication authentication){
65 biletService.buy(tipbilet, LocalDateTime.now(), BILET_STATUS.INACTIVE, authentication.getName());
66 return "redirect:/bilet";
67 }
68
69// @GetMapping("/encode")
70// public String encode(){
71// biletService.encode();
72// return "redirect:/bilet";
73// }
74
75}
Note: See TracBrowser for help on using the repository browser.