[bde8b13] | 1 | package mk.ukim.finki.busngo.web;
|
---|
| 2 |
|
---|
| 3 | import mk.ukim.finki.busngo.model.entities.Patnik;
|
---|
| 4 | import mk.ukim.finki.busngo.model.exceptions.InvalidPatnikIdException;
|
---|
| 5 | import mk.ukim.finki.busngo.service.KaznaZaRegistriranService;
|
---|
| 6 | import mk.ukim.finki.busngo.service.VozenjeService;
|
---|
| 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;
|
---|
[e272096] | 11 | import org.springframework.web.bind.annotation.PathVariable;
|
---|
| 12 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
[bde8b13] | 13 | import org.springframework.web.bind.annotation.RequestMapping;
|
---|
| 14 |
|
---|
| 15 | @Controller
|
---|
| 16 | @RequestMapping("/kazna")
|
---|
| 17 | public class KaznaController {
|
---|
| 18 | private final KaznaZaRegistriranService kaznaZaRegistriranService;
|
---|
| 19 |
|
---|
| 20 | public KaznaController(KaznaZaRegistriranService kaznaZaRegistriranService) {
|
---|
| 21 | this.kaznaZaRegistriranService = kaznaZaRegistriranService;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | @GetMapping()
|
---|
| 25 | public String getKaznaPage(Model model,
|
---|
| 26 | Authentication authentication){
|
---|
| 27 | model.addAttribute("bodyContent", "listKazni");
|
---|
| 28 | Patnik patnik = null;
|
---|
| 29 | try{
|
---|
| 30 | model.addAttribute("kazni", kaznaZaRegistriranService.findAllByPatnik(authentication.getName()));
|
---|
| 31 | }
|
---|
| 32 | catch (InvalidPatnikIdException e){
|
---|
| 33 | model.addAttribute("bodyContent", "listBileti");
|
---|
| 34 | model.addAttribute("hasError", true);
|
---|
| 35 | model.addAttribute("error", e.getMessage());
|
---|
| 36 | return "master-template";
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | return "master-template";
|
---|
| 40 | }
|
---|
[e272096] | 41 |
|
---|
| 42 | @PostMapping("/{id}/pay")
|
---|
| 43 | public String pay(@PathVariable Long id,
|
---|
| 44 | Model model){
|
---|
| 45 | kaznaZaRegistriranService.pay(id);
|
---|
| 46 | return "redirect:/kazna";
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[bde8b13] | 49 | }
|
---|