source: bus-n-go-do-5ta-faza/src/main/java/mk/ukim/finki/busngo/web/KontrolaController.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: 3.8 KB
Line 
1package mk.ukim.finki.busngo.web;
2
3import mk.ukim.finki.busngo.model.entities.Kontroli;
4import mk.ukim.finki.busngo.model.exceptions.UserShouldNotBeTicketedException;
5import mk.ukim.finki.busngo.service.*;
6import org.springframework.security.core.Authentication;
7import org.springframework.stereotype.Controller;
8import org.springframework.ui.Model;
9import org.springframework.web.bind.annotation.*;
10
11@Controller
12@RequestMapping("/kontrola")
13public 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}
Note: See TracBrowser for help on using the repository browser.