source: bus-n-go-do-5ta-faza/src/main/java/mk/ukim/finki/busngo/web/KaznaController.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: 1.8 KB
Line 
1package mk.ukim.finki.busngo.web;
2
3import mk.ukim.finki.busngo.model.entities.Patnik;
4import mk.ukim.finki.busngo.model.exceptions.InvalidPatnikIdException;
5import mk.ukim.finki.busngo.service.KaznaZaRegistriranService;
6import mk.ukim.finki.busngo.service.VozenjeService;
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.PathVariable;
12import org.springframework.web.bind.annotation.PostMapping;
13import org.springframework.web.bind.annotation.RequestMapping;
14
15@Controller
16@RequestMapping("/kazna")
17public 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 }
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
49}
Note: See TracBrowser for help on using the repository browser.