1 | package mk.ukim.finki.busngo.web;
|
---|
2 |
|
---|
3 | import mk.ukim.finki.busngo.model.entities.Avtobus;
|
---|
4 | import mk.ukim.finki.busngo.model.entities.Instancanalinija;
|
---|
5 | import mk.ukim.finki.busngo.model.entities.Linija;
|
---|
6 | import mk.ukim.finki.busngo.service.AvtobusService;
|
---|
7 | import mk.ukim.finki.busngo.service.InstancaNaLinijaService;
|
---|
8 | import mk.ukim.finki.busngo.service.KontrolaService;
|
---|
9 | import mk.ukim.finki.busngo.service.LinijaService;
|
---|
10 | import org.springframework.security.core.Authentication;
|
---|
11 | import org.springframework.stereotype.Controller;
|
---|
12 | import org.springframework.ui.Model;
|
---|
13 | import org.springframework.web.bind.annotation.*;
|
---|
14 |
|
---|
15 | import java.util.List;
|
---|
16 |
|
---|
17 | @Controller
|
---|
18 | @RequestMapping("instanca-na-linija")
|
---|
19 | public class InstancaNaLinijaController {
|
---|
20 | private final InstancaNaLinijaService instancaNaLinijaService;
|
---|
21 | private final LinijaService linijaService;
|
---|
22 | private final AvtobusService avtobusService;
|
---|
23 | private final KontrolaService kontrolaService;
|
---|
24 |
|
---|
25 | public InstancaNaLinijaController(InstancaNaLinijaService instancaNaLinijaService, LinijaService linijaService, AvtobusService avtobusService, KontrolaService kontrolaService) {
|
---|
26 | this.instancaNaLinijaService = instancaNaLinijaService;
|
---|
27 | this.linijaService = linijaService;
|
---|
28 | this.avtobusService = avtobusService;
|
---|
29 | this.kontrolaService = kontrolaService;
|
---|
30 | }
|
---|
31 |
|
---|
32 | @GetMapping()
|
---|
33 | public String getList(Model model){
|
---|
34 | model.addAttribute("bodyContent", "listInstanci");
|
---|
35 | model.addAttribute("inls", instancaNaLinijaService.findAllActive());
|
---|
36 |
|
---|
37 | return "master-template";
|
---|
38 | }
|
---|
39 | @GetMapping("/start")
|
---|
40 | public String getStartPage(Model model){
|
---|
41 | List<Linija> linijaList = linijaService.findAll();
|
---|
42 | List<Avtobus> avtobusList = avtobusService.findAll();
|
---|
43 | model.addAttribute("avtobusi", avtobusList);
|
---|
44 | model.addAttribute("linii", linijaList);
|
---|
45 | model.addAttribute("bodyContent", "startInstanca");
|
---|
46 |
|
---|
47 | return "master-template";
|
---|
48 | }
|
---|
49 |
|
---|
50 | @PostMapping("/start")
|
---|
51 | public String startInstanca(@RequestParam String aRegistracija,
|
---|
52 | @RequestParam Long liId,
|
---|
53 | Model model,
|
---|
54 | Authentication authentication){
|
---|
55 | Instancanalinija start = instancaNaLinijaService.start(liId, aRegistracija, authentication.getName());
|
---|
56 | // model.addAttribute("inl", start);
|
---|
57 | // model.addAttribute("bodyContent", "inlShow");
|
---|
58 |
|
---|
59 | return "redirect:/instanca-na-linija/" + start.getInlId();
|
---|
60 | }
|
---|
61 |
|
---|
62 | @GetMapping("/{inlId}")
|
---|
63 | public String getInlShow(@PathVariable Long inlId,
|
---|
64 | Model model){
|
---|
65 | model.addAttribute("inl", instancaNaLinijaService.findById(inlId));
|
---|
66 | model.addAttribute("kontroli", kontrolaService.findAllByInl(inlId));
|
---|
67 | model.addAttribute("bodyContent", "inlShow");
|
---|
68 |
|
---|
69 | return "master-template";
|
---|
70 | }
|
---|
71 |
|
---|
72 | @PostMapping("/{inlId}/end")
|
---|
73 | public String endInstanca(@PathVariable Long inlId,
|
---|
74 | Authentication authentication){
|
---|
75 | Instancanalinija ended = instancaNaLinijaService.end(inlId, authentication.getName());
|
---|
76 | return "redirect:/instanca-na-linija/" + ended.getInlId();
|
---|
77 | }
|
---|
78 | }
|
---|