source: bus-n-go-do-5ta-faza/src/main/java/mk/ukim/finki/busngo/web/InstancaNaLinijaController.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.1 KB
Line 
1package mk.ukim.finki.busngo.web;
2
3import mk.ukim.finki.busngo.model.entities.Avtobus;
4import mk.ukim.finki.busngo.model.entities.Instancanalinija;
5import mk.ukim.finki.busngo.model.entities.Linija;
6import mk.ukim.finki.busngo.service.AvtobusService;
7import mk.ukim.finki.busngo.service.InstancaNaLinijaService;
8import mk.ukim.finki.busngo.service.KontrolaService;
9import mk.ukim.finki.busngo.service.LinijaService;
10import org.springframework.security.core.Authentication;
11import org.springframework.stereotype.Controller;
12import org.springframework.ui.Model;
13import org.springframework.web.bind.annotation.*;
14
15import java.util.List;
16
17@Controller
18@RequestMapping("instanca-na-linija")
19public 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}
Note: See TracBrowser for help on using the repository browser.