1 | package project.fmo.app.projcetfmo.Web;
|
---|
2 |
|
---|
3 | import org.springframework.stereotype.Controller;
|
---|
4 | import org.springframework.ui.Model;
|
---|
5 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
6 | import org.springframework.web.bind.annotation.PathVariable;
|
---|
7 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
8 | import org.springframework.web.bind.annotation.RequestMapping;
|
---|
9 | import project.fmo.app.projcetfmo.Model.Dostava;
|
---|
10 | import project.fmo.app.projcetfmo.Model.Dostavuvac;
|
---|
11 | import project.fmo.app.projcetfmo.Model.Korisnik;
|
---|
12 | import project.fmo.app.projcetfmo.Service.DostavaService;
|
---|
13 | import project.fmo.app.projcetfmo.Service.DostavuvaceService;
|
---|
14 | import project.fmo.app.projcetfmo.Service.KorisnikService;
|
---|
15 | import project.fmo.app.projcetfmo.Service.NarackaService;
|
---|
16 |
|
---|
17 | import javax.servlet.http.HttpServletRequest;
|
---|
18 | import java.util.List;
|
---|
19 |
|
---|
20 | @Controller
|
---|
21 | @RequestMapping("/delivery")
|
---|
22 | public class DostavaController {
|
---|
23 |
|
---|
24 | private final DostavaService dostavaService;
|
---|
25 | private final DostavuvaceService dostavuvaceService;
|
---|
26 | private final KorisnikService korisnikService;
|
---|
27 | private final NarackaService narackaService;
|
---|
28 |
|
---|
29 | public DostavaController(DostavaService dostavaService, DostavuvaceService dostavuvaceService, KorisnikService korisnikService, NarackaService narackaService) {
|
---|
30 | this.dostavaService = dostavaService;
|
---|
31 | this.dostavuvaceService = dostavuvaceService;
|
---|
32 | this.korisnikService = korisnikService;
|
---|
33 | this.narackaService = narackaService;
|
---|
34 | }
|
---|
35 |
|
---|
36 |
|
---|
37 | @GetMapping
|
---|
38 | public String getDelivery(Model model, HttpServletRequest req){
|
---|
39 | String username = req.getRemoteUser();
|
---|
40 | Korisnik korisnik = korisnikService.findbyImePrezime(username);
|
---|
41 | Dostavuvac dostavuvac = dostavuvaceService.findById(korisnik.getIdKorisnik());
|
---|
42 | List<Dostava> dostavaList = dostavaService.findByIdKorisnikAndStatus(dostavuvac, "za dostava");
|
---|
43 | model.addAttribute("user", korisnik);
|
---|
44 | model.addAttribute("orders", narackaService.findAll());
|
---|
45 | model.addAttribute("delivers", dostavaList);
|
---|
46 | model.addAttribute("bodyContent", "delivery");
|
---|
47 | return "master_template";
|
---|
48 | }
|
---|
49 |
|
---|
50 | @PostMapping("/{id}")
|
---|
51 | public String OrderDelivered(@PathVariable Integer id){
|
---|
52 | dostavaService.edit(id);
|
---|
53 | return "redirect:/delivery";
|
---|
54 | }
|
---|
55 |
|
---|
56 | }
|
---|