Ignore:
Timestamp:
07/07/23 12:14:58 (16 months ago)
Author:
HristijanMitic00 <hristijan.mitic.01@…>
Branches:
main
Parents:
1dd9226
Message:

First commit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/project/fmo/app/projcetfmo/Web/DostavaController.java

    r1dd9226 rd14176d  
    1 package project.fmo.app.projcetfmo.Web;public class DostavaController {
     1package project.fmo.app.projcetfmo.Web;
     2
     3import org.springframework.stereotype.Controller;
     4import org.springframework.ui.Model;
     5import org.springframework.web.bind.annotation.GetMapping;
     6import org.springframework.web.bind.annotation.PathVariable;
     7import org.springframework.web.bind.annotation.PostMapping;
     8import org.springframework.web.bind.annotation.RequestMapping;
     9import project.fmo.app.projcetfmo.Model.Dostava;
     10import project.fmo.app.projcetfmo.Model.Dostavuvac;
     11import project.fmo.app.projcetfmo.Model.Korisnik;
     12import project.fmo.app.projcetfmo.Service.DostavaService;
     13import project.fmo.app.projcetfmo.Service.DostavuvaceService;
     14import project.fmo.app.projcetfmo.Service.KorisnikService;
     15import project.fmo.app.projcetfmo.Service.NarackaService;
     16
     17import javax.servlet.http.HttpServletRequest;
     18import java.util.List;
     19
     20@Controller
     21@RequestMapping("/delivery")
     22public 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
    256}
Note: See TracChangeset for help on using the changeset viewer.