package com.project.beautycenter.web; import com.project.beautycenter.model.Klienti; import com.project.beautycenter.model.Ocena; import com.project.beautycenter.model.Rezervacija; import com.project.beautycenter.model.Uslugi; import com.project.beautycenter.service.*; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import java.util.List; @Controller public class OcenaController { private final UslugiService uslugiService; private final KlientiService klientiService; private final OcenaService ocenaService; private final RezervacijaService rezervacijaService; private final RezervacijaUslugiService rezervacijaUslugiService; public OcenaController(UslugiService uslugiService, KlientiService klientiService, OcenaService ocenaService, RezervacijaService rezervacijaService, RezervacijaUslugiService rezervacijaUslugiService) { this.uslugiService = uslugiService; this.klientiService = klientiService; this.ocenaService = ocenaService; this.rezervacijaService = rezervacijaService; this.rezervacijaUslugiService = rezervacijaUslugiService; } @GetMapping("/services/rate") public String showRate(Model model) { List uslugi = this.uslugiService.findAll(); model.addAttribute("uslugi", uslugi); return "rate.html"; } @PostMapping("/services/rate") public String rate(@RequestParam String uslugi, @RequestParam Integer vrednost, @RequestParam(required = false) String komentar, @RequestParam(required = false) Integer klienti) { Uslugi usluga = this.uslugiService.findbyId(uslugi); Klienti klient = this.klientiService.findById(klienti); this.uslugiService.rate(usluga, vrednost, komentar, klient); return "redirect:/servicesRates"; } @GetMapping("/servicesRates") public String listOfRates(Model model) { List oceni = this.ocenaService.listAll(); List rezOcena = this.ocenaService.listAllWithBrRezNotNull(); model.addAttribute("oceni", oceni); return "oceni.html"; } @PostMapping({"/servicesRates/{id}/delete"}) public String deleteRate(@PathVariable Integer id) { this.ocenaService.delete(id); return "redirect:/servicesRates"; } @GetMapping("/appointment/{id}/rate") public String showRateAppointment(@PathVariable Integer id, Model model) { Rezervacija rez = this.rezervacijaService.findbyId(id); List rezUslugi = this.rezervacijaUslugiService.listAllByBrRez(rez); List uslugi = this.uslugiService.findAll(); model.addAttribute("rez", rez); model.addAttribute("uslugi", uslugi); model.addAttribute("rezUslugi", rezUslugi); return "ratewithAppointment.html"; } @PostMapping("/appointment/{id}/rate") public String RateAppointment( @PathVariable Integer id, @RequestParam List uslugiIds, @RequestParam Integer vrednost, @RequestParam(required = false) String komentar, @RequestParam(required = false) Integer klienti) { List uslugi = this.uslugiService.findAllById(uslugiIds); Klienti klient = this.klientiService.findById(klienti); Rezervacija rez = this.rezervacijaService.findbyId(id); this.ocenaService.rateWithAppointment(rez, uslugi, vrednost, komentar, klient); return "redirect:/servicesRates"; } }