source: src/main/java/com/example/eatys_app/controller/MeniController.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: 3.3 KB
Line 
1package com.example.eatys_app.controller;
2
3import com.example.eatys_app.model.Korisnik;
4import com.example.eatys_app.model.Meni;
5import com.example.eatys_app.model.Restoran;
6import com.example.eatys_app.model.Tip;
7import com.example.eatys_app.service.*;
8import jakarta.servlet.http.HttpServletRequest;
9import org.springframework.stereotype.Controller;
10import org.springframework.ui.Model;
11import org.springframework.web.bind.annotation.GetMapping;
12import org.springframework.web.bind.annotation.PathVariable;
13import org.springframework.web.bind.annotation.PostMapping;
14import org.springframework.web.bind.annotation.RequestParam;
15
16import java.util.List;
17
18@Controller
19public class MeniController {
20
21 private final MeniService meniService;
22 private final RestoranService restoranService;
23 private final TipService tipService;
24 private final KorisnikService korisnikService;
25
26
27 public MeniController(MeniService meniService, RestoranService restoranService, TipService tipService, KorisnikService korisnikService) {
28 this.meniService = meniService;
29 this.restoranService = restoranService;
30 this.tipService = tipService;
31
32 this.korisnikService = korisnikService;
33 }
34
35 @GetMapping( "/menija" )
36 public String showList(Model model, HttpServletRequest req){
37 List<Meni> menija= this.meniService.listAll();
38 List<Restoran> restorani= this.restoranService.listAll();
39 List<Tip>tipovi=this.tipService.listAll();
40 String username = req.getRemoteUser();
41 if(username!=null) {
42 Korisnik korisnik = this.korisnikService.FindByName(username);
43 model.addAttribute("korisnik", korisnik);
44 }
45
46
47 model.addAttribute("menija", menija);
48 model.addAttribute("restorani", restorani);
49 model.addAttribute("tipovi", tipovi);
50
51
52 return "menija.html";
53 }
54
55 @GetMapping("/menija/add")
56 public String showAdd(Model model) {
57 List<Restoran> restorani= this.restoranService.listAll();
58 List<Tip>tipovi=this.tipService.listAll();
59 model.addAttribute("restorani", restorani);
60 model.addAttribute("tipovi", tipovi);
61 return "formMeni.html";
62 }
63
64 @GetMapping("/menija/{id}/edit")
65 public String showEdit(@PathVariable Integer id, Model model) {
66 Meni meni=this.meniService.findById(id);
67 List<Restoran> restorani= this.restoranService.listAll();
68 List<Tip>tipovi=this.tipService.listAll();
69 model.addAttribute("meni", meni);
70 model.addAttribute("restorani", restorani);
71 model.addAttribute("tipovi", tipovi);
72 return "formMeni.html";
73 }
74
75 @PostMapping("/menija/")
76 public String create(@RequestParam Integer tipId,
77 @RequestParam Integer restoranId
78 ){
79 this.meniService.create(tipId, restoranId);
80 return "redirect:/menija";
81 }
82
83 @PostMapping("/menija/{id}")
84 public String update(@PathVariable Integer id,
85 @RequestParam Integer tipId,
86 @RequestParam Integer restoranId
87 ){
88 this.meniService.update( id,tipId, restoranId);
89 return "redirect:/menija";
90 }
91
92 @PostMapping("/menija/{id}/delete")
93 public String delete(@PathVariable Integer id) {
94 this.meniService.delete(id);
95 return "redirect:/menija";
96 }
97
98
99
100}
Note: See TracBrowser for help on using the repository browser.