[850b344] | 1 | package com.project.beautycenter.web;
|
---|
| 2 |
|
---|
| 3 | import com.project.beautycenter.model.Klienti;
|
---|
| 4 | import com.project.beautycenter.model.Ocena;
|
---|
| 5 | import com.project.beautycenter.model.Rezervacija;
|
---|
| 6 | import com.project.beautycenter.model.Uslugi;
|
---|
| 7 | import com.project.beautycenter.service.*;
|
---|
| 8 | import org.springframework.stereotype.Controller;
|
---|
| 9 | import org.springframework.ui.Model;
|
---|
| 10 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
| 11 | import org.springframework.web.bind.annotation.PathVariable;
|
---|
| 12 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
| 13 | import org.springframework.web.bind.annotation.RequestParam;
|
---|
| 14 |
|
---|
| 15 | import java.util.List;
|
---|
| 16 |
|
---|
| 17 | @Controller
|
---|
| 18 | public class OcenaController {
|
---|
| 19 |
|
---|
| 20 | private final UslugiService uslugiService;
|
---|
| 21 | private final KlientiService klientiService;
|
---|
| 22 | private final OcenaService ocenaService;
|
---|
| 23 | private final RezervacijaService rezervacijaService;
|
---|
| 24 | private final RezervacijaUslugiService rezervacijaUslugiService;
|
---|
| 25 |
|
---|
| 26 | public OcenaController(UslugiService uslugiService, KlientiService klientiService, OcenaService ocenaService, RezervacijaService rezervacijaService, RezervacijaUslugiService rezervacijaUslugiService) {
|
---|
| 27 | this.uslugiService = uslugiService;
|
---|
| 28 | this.klientiService = klientiService;
|
---|
| 29 | this.ocenaService = ocenaService;
|
---|
| 30 | this.rezervacijaService = rezervacijaService;
|
---|
| 31 | this.rezervacijaUslugiService = rezervacijaUslugiService;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | @GetMapping("/services/rate")
|
---|
| 35 | public String showRate(Model model) {
|
---|
| 36 | List<Uslugi> uslugi = this.uslugiService.findAll();
|
---|
| 37 | model.addAttribute("uslugi", uslugi);
|
---|
| 38 |
|
---|
| 39 | return "rate.html";
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | @PostMapping("/services/rate")
|
---|
| 43 | public String rate(@RequestParam String uslugi,
|
---|
| 44 | @RequestParam Integer vrednost,
|
---|
| 45 | @RequestParam(required = false) String komentar,
|
---|
| 46 | @RequestParam(required = false) Integer klienti) {
|
---|
| 47 | Uslugi usluga = this.uslugiService.findbyId(uslugi);
|
---|
| 48 | Klienti klient = this.klientiService.findById(klienti);
|
---|
| 49 |
|
---|
| 50 | this.uslugiService.rate(usluga, vrednost, komentar, klient);
|
---|
| 51 | return "redirect:/servicesRates";
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | @GetMapping("/servicesRates")
|
---|
| 55 | public String listOfRates(Model model) {
|
---|
| 56 | List<Ocena> oceni = this.ocenaService.listAll();
|
---|
| 57 | List<Ocena> rezOcena = this.ocenaService.listAllWithBrRezNotNull();
|
---|
| 58 | model.addAttribute("oceni", oceni);
|
---|
| 59 | return "oceni.html";
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | @PostMapping({"/servicesRates/{id}/delete"})
|
---|
| 63 | public String deleteRate(@PathVariable Integer id) {
|
---|
| 64 |
|
---|
| 65 | this.ocenaService.delete(id);
|
---|
| 66 | return "redirect:/servicesRates";
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | @GetMapping("/appointment/{id}/rate")
|
---|
| 70 | public String showRateAppointment(@PathVariable Integer id, Model model) {
|
---|
| 71 | Rezervacija rez = this.rezervacijaService.findbyId(id);
|
---|
| 72 | List<Uslugi> rezUslugi = this.rezervacijaUslugiService.listAllByBrRez(rez);
|
---|
| 73 | List<Uslugi> uslugi = this.uslugiService.findAll();
|
---|
| 74 | model.addAttribute("rez", rez);
|
---|
| 75 | model.addAttribute("uslugi", uslugi);
|
---|
| 76 | model.addAttribute("rezUslugi", rezUslugi);
|
---|
| 77 |
|
---|
| 78 | return "ratewithAppointment.html";
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | @PostMapping("/appointment/{id}/rate")
|
---|
| 82 | public String RateAppointment(
|
---|
| 83 | @PathVariable Integer id,
|
---|
| 84 | @RequestParam List<String> uslugiIds,
|
---|
| 85 | @RequestParam Integer vrednost,
|
---|
| 86 | @RequestParam(required = false) String komentar,
|
---|
| 87 | @RequestParam(required = false) Integer klienti) {
|
---|
| 88 |
|
---|
| 89 | List<Uslugi> uslugi = this.uslugiService.findAllById(uslugiIds);
|
---|
| 90 | Klienti klient = this.klientiService.findById(klienti);
|
---|
| 91 | Rezervacija rez = this.rezervacijaService.findbyId(id);
|
---|
| 92 | this.ocenaService.rateWithAppointment(rez, uslugi, vrednost, komentar, klient);
|
---|
| 93 | return "redirect:/servicesRates";
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | }
|
---|