- Timestamp:
- 02/03/24 18:08:44 (9 months ago)
- Branches:
- master
- Children:
- cab1b7d
- Parents:
- aea04dd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/cookbook/controller/HomeController.java
raea04dd rd4d8fb9 2 2 3 3 4 import com.example.cookbook.model.Komentar; 5 import com.example.cookbook.model.Recept; 6 import com.example.cookbook.model.Slika; 7 import com.example.cookbook.model.Sostojka; 4 import com.example.cookbook.model.*; 8 5 import com.example.cookbook.model.exception.ReceptNeEPronajdenException; 9 import com.example.cookbook.service.KomentariService; 10 import com.example.cookbook.service.ReceptService; 11 import com.example.cookbook.service.SlikiService; 12 import com.example.cookbook.service.SostojkiService; 6 import com.example.cookbook.service.*; 13 7 import org.springframework.stereotype.Controller; 14 8 import org.springframework.ui.Model; 15 9 import org.springframework.web.bind.annotation.GetMapping; 16 10 import org.springframework.web.bind.annotation.PathVariable; 11 import org.springframework.web.bind.annotation.PostMapping; 12 import org.springframework.web.bind.annotation.RequestParam; 17 13 18 14 import java.sql.SQLException; 15 import java.time.LocalDateTime; 19 16 import java.util.List; 20 17 … … 29 26 private final KomentariService komentariService; 30 27 28 private final KorisniciService korisniciService; 29 31 30 public HomeController(ReceptService receptService, 32 31 SlikiService slikiService, 33 SostojkiService sostojkiService, KomentariService komentariService ) {32 SostojkiService sostojkiService, KomentariService komentariService, KorisniciService korisniciService) { 34 33 35 34 this.receptService = receptService; … … 37 36 this.sostojkiService = sostojkiService; 38 37 this.komentariService = komentariService; 38 this.korisniciService = korisniciService; 39 39 } 40 40 … … 59 59 List<Sostojka> sostojki; 60 60 List<Komentar> komentari; 61 List<Korisnik> posetiteli; 61 62 try { 62 63 recept = receptService.findById(id); … … 64 65 sostojki = sostojkiService.findAllById(id); 65 66 komentari = komentariService.findAllById(id); 67 posetiteli = korisniciService.findAllByRole(TipKorisnik.Posetitel); 66 68 } catch (SQLException e) { 67 69 return "redirect:/error-page/SQL%20Exception"; … … 73 75 model.addAttribute("sostojki", sostojki); 74 76 model.addAttribute("komentari", komentari); 77 model.addAttribute("posetiteli", posetiteli); 75 78 return "recept"; 79 } 80 81 @PostMapping("/komentar/{id}") 82 public String processKomentar(@PathVariable Long id, 83 @RequestParam Integer ocena, 84 @RequestParam String komentar, 85 @RequestParam String telefon){ 86 if (id == null){ 87 return "redirect:/error-page/Ne%20dodavanje%20komentar(Identifikatorot%20na%20receptot%20ne%20postoi)"; 88 } 89 try { 90 komentariService.add(telefon, id, ocena, komentar); 91 } catch (SQLException e) { 92 return "redirect:/error-page/SQL%20Exception"; 93 }catch (IllegalArgumentException e){ 94 return "redirect:/error-page/Illegal%20Arguments"; 95 } 96 return "redirect:/recept/" + id; 76 97 } 77 98
Note:
See TracChangeset
for help on using the changeset viewer.