1 | package mk.finki.ukim.mk.vehiclerent.web;
|
---|
2 |
|
---|
3 | import mk.finki.ukim.mk.vehiclerent.enumerations.ROLES;
|
---|
4 | import mk.finki.ukim.mk.vehiclerent.generated_model.KlientiEntity;
|
---|
5 | import mk.finki.ukim.mk.vehiclerent.generated_model.VozilaEntity;
|
---|
6 | import mk.finki.ukim.mk.vehiclerent.generated_model.VraboteniEntity;
|
---|
7 | import mk.finki.ukim.mk.vehiclerent.service.VoziloService;
|
---|
8 | import mk.finki.ukim.mk.vehiclerent.service.impl.RezervacijaServiceImpl;
|
---|
9 | import mk.finki.ukim.mk.vehiclerent.service.impl.VoziloServiceImpl;
|
---|
10 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
11 | import org.springframework.security.core.context.SecurityContextHolder;
|
---|
12 | import org.springframework.stereotype.Controller;
|
---|
13 | import org.springframework.ui.Model;
|
---|
14 | import org.springframework.web.bind.annotation.*;
|
---|
15 |
|
---|
16 | import java.util.List;
|
---|
17 |
|
---|
18 | @Controller
|
---|
19 | public class VoziloController {
|
---|
20 | @Autowired
|
---|
21 | private final VoziloServiceImpl voziloService;
|
---|
22 |
|
---|
23 | @Autowired
|
---|
24 | private final RezervacijaServiceImpl rezervacijaService;
|
---|
25 |
|
---|
26 | public VoziloController(VoziloServiceImpl service, RezervacijaServiceImpl rezervacijaService) {
|
---|
27 | this.voziloService = service;
|
---|
28 | this.rezervacijaService = rezervacijaService;
|
---|
29 | }
|
---|
30 |
|
---|
31 | @RequestMapping(value = "/vehicles", method = RequestMethod.GET)
|
---|
32 | public String showcars(Model model){
|
---|
33 | List<VozilaEntity> vozila = voziloService.listAll();
|
---|
34 | model.addAttribute("vozila",vozila);
|
---|
35 | return "vehicles.html";
|
---|
36 | }
|
---|
37 |
|
---|
38 | @RequestMapping(value = "/addVehicle", method = RequestMethod.GET)
|
---|
39 | public String addVehiclea(Model model){
|
---|
40 | model.addAttribute("vozilo",new VozilaEntity());
|
---|
41 | return "addVehicle.html";
|
---|
42 | }
|
---|
43 |
|
---|
44 | @RequestMapping(value = "/addVehicle", method = RequestMethod.POST)
|
---|
45 | public String addVehiclea(Model model, VozilaEntity vozilo){
|
---|
46 | voziloService.create(1,vozilo.getModel(),vozilo.getMarka(), vozilo.getRegtab(), vozilo.getCenavozi());
|
---|
47 | return "redirect:/";
|
---|
48 | }
|
---|
49 |
|
---|
50 | @RequestMapping(value = "/rentVehicle/{id}", method = RequestMethod.GET)
|
---|
51 | public String showcars(Model model, @PathVariable(value = "id") String id){
|
---|
52 | Object principal = SecurityContextHolder. getContext(). getAuthentication(). getPrincipal();
|
---|
53 | String embg = "";
|
---|
54 | ROLES role = null;
|
---|
55 | if(principal instanceof KlientiEntity){
|
---|
56 | role = ROLES.KLIENT;
|
---|
57 | embg = ((KlientiEntity) principal).getEmbgk();
|
---|
58 | }else if(principal instanceof VraboteniEntity){
|
---|
59 | role = ROLES.VRABOTEN;
|
---|
60 | embg = ((VraboteniEntity) principal).getEmbgv();
|
---|
61 | }
|
---|
62 | rezervacijaService.rentVehicle(id,embg,role);
|
---|
63 | return "redirect:/";
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 | }
|
---|