source: src/main/java/com/example/eatys_app/controller/CenaController.java@ b3f2adb

Last change on this file since b3f2adb was b3f2adb, checked in by Aleksandar Siljanoski <acewow3@…>, 14 months ago

Adding project to repo

  • Property mode set to 100644
File size: 2.9 KB
Line 
1package com.example.eatys_app.controller;
2
3
4import com.example.eatys_app.model.Cena;
5import com.example.eatys_app.model.Meni;
6import com.example.eatys_app.model.Obrok;
7import com.example.eatys_app.service.CenaService;
8import com.example.eatys_app.service.ObrokService;
9import org.springframework.format.annotation.DateTimeFormat;
10import org.springframework.stereotype.Controller;
11import org.springframework.ui.Model;
12import org.springframework.web.bind.annotation.GetMapping;
13import org.springframework.web.bind.annotation.PathVariable;
14import org.springframework.web.bind.annotation.PostMapping;
15import org.springframework.web.bind.annotation.RequestParam;
16
17import java.time.LocalDateTime;
18import java.util.Date;
19import java.util.List;
20
21@Controller
22public 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}
Note: See TracBrowser for help on using the repository browser.