1 | package com.example.cookbook.controller;
|
---|
2 |
|
---|
3 |
|
---|
4 | import com.example.cookbook.model.DostavaDTO;
|
---|
5 | import com.example.cookbook.model.Naracka;
|
---|
6 | import com.example.cookbook.model.Recept;
|
---|
7 | import com.example.cookbook.model.Stavka;
|
---|
8 | import com.example.cookbook.service.NarackiService;
|
---|
9 | import org.springframework.stereotype.Controller;
|
---|
10 | import org.springframework.ui.Model;
|
---|
11 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
12 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
13 | import org.springframework.web.bind.annotation.RequestParam;
|
---|
14 |
|
---|
15 | import java.sql.SQLException;
|
---|
16 | import java.time.LocalDateTime;
|
---|
17 | import java.util.List;
|
---|
18 |
|
---|
19 | @Controller
|
---|
20 | public class VrabotenController {
|
---|
21 |
|
---|
22 | private final NarackiService narcakiService;
|
---|
23 |
|
---|
24 | public VrabotenController(NarackiService narcakiService) {
|
---|
25 | this.narcakiService = narcakiService;
|
---|
26 | }
|
---|
27 |
|
---|
28 |
|
---|
29 | @GetMapping("/naracki")
|
---|
30 | public String getNaracki(Model model){
|
---|
31 |
|
---|
32 | List<Naracka> naracki = null;
|
---|
33 | try {
|
---|
34 | naracki = narcakiService.listAll();
|
---|
35 | } catch (SQLException e) {
|
---|
36 | return "redirect:/error-page/SQL%20Exception";
|
---|
37 | }
|
---|
38 | model.addAttribute("naracki", naracki);
|
---|
39 | return "naracki";
|
---|
40 | }
|
---|
41 |
|
---|
42 | @GetMapping("/naracki/naracka")
|
---|
43 | public String getNarackaPage(@RequestParam String telefon,
|
---|
44 | @RequestParam LocalDateTime vreme,
|
---|
45 | Model model){
|
---|
46 | List<DostavaDTO> podatoci = null;
|
---|
47 | List<Stavka> stavkiVoNaracka = null;
|
---|
48 | try {
|
---|
49 | stavkiVoNaracka = narcakiService.findByTelAndVreme(telefon, vreme);
|
---|
50 | podatoci = narcakiService.findDataForDostava(telefon, vreme);
|
---|
51 | } catch (SQLException e) {
|
---|
52 | return "redirect:/error-page/SQL%20Exception";
|
---|
53 | }
|
---|
54 |
|
---|
55 | model.addAttribute("stavki", stavkiVoNaracka);
|
---|
56 | model.addAttribute("podatoci", podatoci);
|
---|
57 |
|
---|
58 | return "stavka";
|
---|
59 | }
|
---|
60 | }
|
---|