package com.project.beautycenter.web; import com.project.beautycenter.model.*; 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 AppointmentController { private final KlientiService klientiService; private final RezervacijaService rezervacijaService; private final UslugiService uslugiService; private final TerminiService terminiService; private final RezervacijaUslugiService rezervacijaUslugiService; private final UplataService uplataService; public AppointmentController(KlientiService klientiService, RezervacijaService rezervacijaService, UslugiService uslugiService, TerminiService terminiService, RezervacijaUslugiService rezervacijaUslugiService, UplataService uplataService) { this.klientiService = klientiService; this.rezervacijaService = rezervacijaService; this.uslugiService = uslugiService; this.terminiService = terminiService; this.rezervacijaUslugiService = rezervacijaUslugiService; this.uplataService = uplataService; } @GetMapping("/appointment") public String showListAppointments( Model model) { List rezervacii = this.rezervacijaService.listAll(); List uslugi = this.uslugiService.findAll(); List rezUslugi = this.rezervacijaUslugiService.listAll(); model.addAttribute("rezervacii",rezervacii); model.addAttribute("uslugi", uslugi); model.addAttribute("rezUslugi", rezUslugi); return "appointmentsList.html"; } @GetMapping( "/makeAppointment") public String MakeAppointment(Model model) { List uslugi = this.uslugiService.findAll(); List klienti = this.klientiService.listAll(); List nerezTerm = this.terminiService.listAllNotReserved(); model.addAttribute("uslugi", uslugi); model.addAttribute("klienti", klienti); model.addAttribute("nerezTerm",nerezTerm); return "appointment_form.html"; } @GetMapping("/appointment/{id}/edit") public String showEdit(@PathVariable Integer id, Model model) { Rezervacija rezervacija = this.rezervacijaService.findbyId(id); List uslugi = this.uslugiService.findAll(); List nerezTerm = this.terminiService.listAllNotReserved(); List rezerviraniUslugi = this.rezervacijaUslugiService.listAllByBrRez(rezervacija); model.addAttribute("rezerviraniUslugi",rezerviraniUslugi); model.addAttribute("rezervacija",rezervacija); model.addAttribute("uslugi", uslugi); model.addAttribute("nerezTerm",nerezTerm); return "editAppointment.html"; } @PostMapping("/makeAppointment") public String create(@RequestParam List uslugiIds, @RequestParam Integer klientId, @RequestParam Integer terminId ) { List uslugi = this.uslugiService.findAllById(uslugiIds); Klienti klient = this.klientiService.findById(klientId); Rezervacija rezervacija = this.rezervacijaService.create(klientId,terminId,uslugi); return "redirect:/appointment"; } @PostMapping("/appointment/{id}") public String update(@PathVariable Integer id, @RequestParam List uslugiIds, @RequestParam Integer klientId, @RequestParam Integer terminId) { this.rezervacijaService.update(id, uslugiIds, klientId,terminId); return "redirect:/appointment"; } @PostMapping({"/appointment/{id}/delete"}) public String delete(@PathVariable Integer id) { this.rezervacijaService.delete(id); return "redirect:/appointment"; } @GetMapping("/payment") public String showCreditCard() { return "creditCard_form.html"; } }