[b101b69] | 1 | package mk.ukim.finki.busngo.web;
|
---|
| 2 |
|
---|
| 3 | import mk.ukim.finki.busngo.model.enums.BILET_STATUS;
|
---|
| 4 | import mk.ukim.finki.busngo.service.AuthService;
|
---|
| 5 | import mk.ukim.finki.busngo.service.BiletService;
|
---|
| 6 | import mk.ukim.finki.busngo.service.TipBiletService;
|
---|
| 7 | import org.springframework.security.core.Authentication;
|
---|
| 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.PostMapping;
|
---|
| 12 | import org.springframework.web.bind.annotation.RequestMapping;
|
---|
| 13 | import org.springframework.web.bind.annotation.RequestParam;
|
---|
| 14 |
|
---|
| 15 | import java.time.LocalDateTime;
|
---|
| 16 |
|
---|
| 17 | @Controller
|
---|
| 18 | @RequestMapping("/bilet")
|
---|
| 19 | public 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 | }
|
---|