source: src/main/java/mk/ukim/finki/busngo/web/BiletController.java@ b101b69

Last change on this file since b101b69 was b101b69, checked in by ppaunovski <paunovskipavel@…>, 6 months ago

initial classes, no inheritance yet v2

  • Property mode set to 100644
File size: 2.0 KB
Line 
1package mk.ukim.finki.busngo.web;
2
3import mk.ukim.finki.busngo.model.enums.BILET_STATUS;
4import mk.ukim.finki.busngo.service.AuthService;
5import mk.ukim.finki.busngo.service.BiletService;
6import mk.ukim.finki.busngo.service.TipBiletService;
7import org.springframework.security.core.Authentication;
8import org.springframework.stereotype.Controller;
9import org.springframework.ui.Model;
10import org.springframework.web.bind.annotation.GetMapping;
11import org.springframework.web.bind.annotation.PostMapping;
12import org.springframework.web.bind.annotation.RequestMapping;
13import org.springframework.web.bind.annotation.RequestParam;
14
15import java.time.LocalDateTime;
16
17@Controller
18@RequestMapping("/bilet")
19public class BiletController {
20 private final BiletService biletService;
21 private final TipBiletService tipBiletService;
22 private final AuthService authService;
23
24 public BiletController(BiletService biletService, TipBiletService tipBiletService, AuthService authService) {
25 this.biletService = biletService;
26 this.tipBiletService = tipBiletService;
27 this.authService = authService;
28 }
29
30 @GetMapping()
31 public String getAllBileti(@RequestParam(required = false) Long id,
32 @RequestParam(required = false) BILET_STATUS status,
33 Model model){
34 model.addAttribute("bodyContent", "listBileti");
35 model.addAttribute("bileti", biletService.listAll());
36 return "master-template";
37 }
38
39 @GetMapping("/kupi")
40 public String getKupiPage(Model model){
41 model.addAttribute("bodyContent", "kupiBilet");
42 model.addAttribute("tipbileti", tipBiletService.listAll());
43 return "master-template";
44 }
45
46 @PostMapping("/kupi")
47 public String kupiBilet(@RequestParam Long tipbilet, Authentication authentication){
48 biletService.buy(tipbilet, LocalDateTime.now(), BILET_STATUS.INACTIVE, authentication.getName());
49 return "redirect:/bilet";
50 }
51
52}
Note: See TracBrowser for help on using the repository browser.