1 | package mk.ukim.finki.busngo.web;
|
---|
2 |
|
---|
3 | import mk.ukim.finki.busngo.model.entities.Kontroli;
|
---|
4 | import mk.ukim.finki.busngo.model.exceptions.UserShouldNotBeTicketedException;
|
---|
5 | import mk.ukim.finki.busngo.service.*;
|
---|
6 | import org.springframework.security.core.Authentication;
|
---|
7 | import org.springframework.stereotype.Controller;
|
---|
8 | import org.springframework.ui.Model;
|
---|
9 | import org.springframework.web.bind.annotation.*;
|
---|
10 |
|
---|
11 | @Controller
|
---|
12 | @RequestMapping("/kontrola")
|
---|
13 | public class KontrolaController {
|
---|
14 |
|
---|
15 | private final KontrolaService kontrolaService;
|
---|
16 | private final KaznaZaRegistriranService kaznaZaRegistriranService;
|
---|
17 | private final KaznaZaNeregistriranService kaznaZaNeregistriranService;
|
---|
18 | private final KaznaService kaznaService;
|
---|
19 | private final PatnikService patnikService;
|
---|
20 | private final VozacService vozacService;
|
---|
21 | private final InstancaNaLinijaService instancaNaLinijaService;
|
---|
22 |
|
---|
23 | public KontrolaController(KontrolaService kontrolaService, KaznaZaRegistriranService kaznaZaRegistriranService, KaznaZaNeregistriranService kaznaZaNeregistriranService, KaznaService kaznaService, PatnikService patnikService, VozacService vozacService, InstancaNaLinijaService instancaNaLinijaService) {
|
---|
24 | this.kontrolaService = kontrolaService;
|
---|
25 | this.kaznaZaRegistriranService = kaznaZaRegistriranService;
|
---|
26 | this.kaznaZaNeregistriranService = kaznaZaNeregistriranService;
|
---|
27 | this.kaznaService = kaznaService;
|
---|
28 | this.patnikService = patnikService;
|
---|
29 | this.vozacService = vozacService;
|
---|
30 | this.instancaNaLinijaService = instancaNaLinijaService;
|
---|
31 | }
|
---|
32 |
|
---|
33 | @GetMapping("/{kontrolaId}")
|
---|
34 | public String get(@PathVariable Long kontrolaId,
|
---|
35 | Model model){
|
---|
36 | model.addAttribute("bodyContent", "kontrola");
|
---|
37 | Kontroli kontroli = kontrolaService.findById(kontrolaId);
|
---|
38 |
|
---|
39 | model.addAttribute("kontrola", kontroli);
|
---|
40 | model.addAttribute("kazni", kaznaService.findAllByKontrolaId(kontrolaId));
|
---|
41 | model.addAttribute("patnici", patnikService.listAll());
|
---|
42 | return "master-template";
|
---|
43 | }
|
---|
44 | @GetMapping("/start-for/{inlId}")
|
---|
45 | public String getStartPage(@PathVariable Long inlId,
|
---|
46 | Model model,
|
---|
47 | Authentication authentication){
|
---|
48 | model.addAttribute("bodyContent", "kontrola");
|
---|
49 | Kontroli kontroli = kontrolaService.create(inlId, authentication.getName());
|
---|
50 |
|
---|
51 | model.addAttribute("kontrola", kontroli);
|
---|
52 | return "redirect:/kontrola/" + kontroli.getKontrolaId();
|
---|
53 | }
|
---|
54 |
|
---|
55 | @PostMapping("/{kontrolaId}/kazni-registriran")
|
---|
56 | public String kazniRegistriran(@PathVariable Long kontrolaId,
|
---|
57 | @RequestParam String dokument,
|
---|
58 | @RequestParam Double iznos,
|
---|
59 | @RequestParam Long patnik,
|
---|
60 | Authentication authentication){
|
---|
61 | try {
|
---|
62 |
|
---|
63 | kaznaZaRegistriranService.create(kontrolaId, dokument, iznos, patnik, authentication.getName());
|
---|
64 | }
|
---|
65 | catch (UserShouldNotBeTicketedException exception){
|
---|
66 | return "redirect:/kontrola/" + kontrolaId;
|
---|
67 | }
|
---|
68 |
|
---|
69 | return "redirect:/kontrola/" + kontrolaId;
|
---|
70 | }
|
---|
71 |
|
---|
72 | @PostMapping("/{kontrolaId}/kazni-neregistriran")
|
---|
73 | public String kazniNeregistriran(@PathVariable Long kontrolaId,
|
---|
74 | @RequestParam String dokument,
|
---|
75 | @RequestParam Double iznos,
|
---|
76 | @RequestParam String telefon,
|
---|
77 | @RequestParam String ime,
|
---|
78 | @RequestParam String adresa,
|
---|
79 | Authentication authentication){
|
---|
80 |
|
---|
81 | kaznaZaNeregistriranService.create(kontrolaId, dokument, iznos, telefon, ime, adresa, authentication.getName());
|
---|
82 |
|
---|
83 | return "redirect:/kontrola/" + kontrolaId;
|
---|
84 | }
|
---|
85 | }
|
---|