source: src/main/java/com/example/cookbook/controller/VrabotenController.java

Last change on this file was a226bc3, checked in by Blazho <aleksandar.blazhevski@…>, 9 months ago

Vraboteniot ja planira dostavata na narackata(https://develop.finki.ukim.mk/projects/cbdb/wiki/useCase10)

  • Property mode set to 100644
File size: 1.9 KB
Line 
1package com.example.cookbook.controller;
2
3
4import com.example.cookbook.model.DostavaDTO;
5import com.example.cookbook.model.Naracka;
6import com.example.cookbook.model.Recept;
7import com.example.cookbook.model.Stavka;
8import com.example.cookbook.service.NarackiService;
9import org.springframework.stereotype.Controller;
10import org.springframework.ui.Model;
11import org.springframework.web.bind.annotation.GetMapping;
12import org.springframework.web.bind.annotation.PostMapping;
13import org.springframework.web.bind.annotation.RequestParam;
14
15import java.sql.SQLException;
16import java.time.LocalDateTime;
17import java.util.List;
18
19@Controller
20public 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}
Note: See TracBrowser for help on using the repository browser.