[b3f2adb] | 1 | package com.example.eatys_app.controller;
|
---|
| 2 |
|
---|
| 3 |
|
---|
| 4 | import com.example.eatys_app.model.Cena;
|
---|
| 5 | import com.example.eatys_app.model.Meni;
|
---|
| 6 | import com.example.eatys_app.model.Obrok;
|
---|
| 7 | import com.example.eatys_app.service.CenaService;
|
---|
| 8 | import com.example.eatys_app.service.ObrokService;
|
---|
| 9 | import org.springframework.format.annotation.DateTimeFormat;
|
---|
| 10 | import org.springframework.stereotype.Controller;
|
---|
| 11 | import org.springframework.ui.Model;
|
---|
| 12 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
| 13 | import org.springframework.web.bind.annotation.PathVariable;
|
---|
| 14 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
| 15 | import org.springframework.web.bind.annotation.RequestParam;
|
---|
| 16 |
|
---|
| 17 | import java.time.LocalDateTime;
|
---|
| 18 | import java.util.Date;
|
---|
| 19 | import java.util.List;
|
---|
| 20 |
|
---|
| 21 | @Controller
|
---|
| 22 | public class CenaController {
|
---|
| 23 |
|
---|
| 24 | private final CenaService cenaService;
|
---|
| 25 | private final ObrokService obrokService;
|
---|
| 26 |
|
---|
| 27 | public CenaController(CenaService cenaService, ObrokService obrokService) {
|
---|
| 28 | this.cenaService = cenaService;
|
---|
| 29 | this.obrokService = obrokService;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | @GetMapping( "/ceni" )
|
---|
| 33 | public String showList(Model model){
|
---|
| 34 | List<Obrok> obroci= this.obrokService.listAll();
|
---|
| 35 | List<Cena> ceni= this.cenaService.listAll();
|
---|
| 36 |
|
---|
| 37 | model.addAttribute("obroci", obroci);
|
---|
| 38 | model.addAttribute("ceni", ceni);
|
---|
| 39 | return "ceni.html";
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | @GetMapping("/ceni/add")
|
---|
| 43 | public String showAdd(Model model) {
|
---|
| 44 | List<Obrok> obroci= this.obrokService.listAll();
|
---|
| 45 | model.addAttribute("obroci", obroci);
|
---|
| 46 | return "formCena.html";
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | @GetMapping("/ceni/{id}/edit")
|
---|
| 50 | public String showEdit(@PathVariable Integer id, Model model ) {
|
---|
| 51 | Cena cena=this.cenaService.findbyUniqueId(id);
|
---|
| 52 | List<Obrok> obroci= this.obrokService.listAll();
|
---|
| 53 | model.addAttribute("cena", cena);
|
---|
| 54 | model.addAttribute("obroci", obroci);
|
---|
| 55 | return "formCena.html";
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | @PostMapping("/ceni/")
|
---|
| 59 | public String create(@RequestParam Integer id,
|
---|
| 60 | @RequestParam Integer obrokId,
|
---|
| 61 | @RequestParam Integer cenaIznos,
|
---|
| 62 | @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date cenaVaziOd,
|
---|
| 63 | @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date cenaVaziDo
|
---|
| 64 | ){
|
---|
| 65 | this.cenaService.create(id,obrokId, cenaIznos,cenaVaziOd,cenaVaziDo);
|
---|
| 66 | return "redirect:/obroci";
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | @PostMapping("/ceni/{id}")
|
---|
| 70 | public String edit( @PathVariable Integer id,
|
---|
| 71 | @RequestParam Integer obrokId,
|
---|
| 72 | @RequestParam Integer cenaIznos,
|
---|
| 73 | @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date cenaVaziOd,
|
---|
| 74 | @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date cenaVaziDo
|
---|
| 75 | ){
|
---|
| 76 | this.cenaService.update(id,obrokId, cenaIznos,cenaVaziOd,cenaVaziDo);
|
---|
| 77 | return "redirect:/obroci";
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 | }
|
---|