[850b344] | 1 | package com.project.beautycenter.web;
|
---|
| 2 |
|
---|
| 3 | import com.project.beautycenter.model.*;
|
---|
| 4 | import com.project.beautycenter.service.*;
|
---|
| 5 | import org.springframework.stereotype.Controller;
|
---|
| 6 | import org.springframework.ui.Model;
|
---|
| 7 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
| 8 | import org.springframework.web.bind.annotation.PathVariable;
|
---|
| 9 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
| 10 | import org.springframework.web.bind.annotation.RequestParam;
|
---|
| 11 |
|
---|
| 12 | import java.util.List;
|
---|
| 13 |
|
---|
| 14 | @Controller
|
---|
| 15 | public class AppointmentController {
|
---|
| 16 |
|
---|
| 17 | private final KlientiService klientiService;
|
---|
| 18 | private final RezervacijaService rezervacijaService;
|
---|
| 19 | private final UslugiService uslugiService;
|
---|
| 20 | private final TerminiService terminiService;
|
---|
| 21 | private final RezervacijaUslugiService rezervacijaUslugiService;
|
---|
| 22 | private final UplataService uplataService;
|
---|
| 23 |
|
---|
| 24 | public AppointmentController(KlientiService klientiService, RezervacijaService rezervacijaService,
|
---|
| 25 | UslugiService uslugiService, TerminiService terminiService, RezervacijaUslugiService rezervacijaUslugiService, UplataService uplataService) {
|
---|
| 26 | this.klientiService = klientiService;
|
---|
| 27 | this.rezervacijaService = rezervacijaService;
|
---|
| 28 | this.uslugiService = uslugiService;
|
---|
| 29 | this.terminiService = terminiService;
|
---|
| 30 | this.rezervacijaUslugiService = rezervacijaUslugiService;
|
---|
| 31 | this.uplataService = uplataService;
|
---|
| 32 | }
|
---|
| 33 | @GetMapping("/appointment")
|
---|
| 34 | public String showListAppointments( Model model) {
|
---|
| 35 | List<Rezervacija> rezervacii = this.rezervacijaService.listAll();
|
---|
| 36 | List<Uslugi> uslugi = this.uslugiService.findAll();
|
---|
| 37 | List<RezervacijaUslugi> rezUslugi = this.rezervacijaUslugiService.listAll();
|
---|
| 38 |
|
---|
| 39 | model.addAttribute("rezervacii",rezervacii);
|
---|
| 40 | model.addAttribute("uslugi", uslugi);
|
---|
| 41 | model.addAttribute("rezUslugi", rezUslugi);
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | return "appointmentsList.html";
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | @GetMapping( "/makeAppointment")
|
---|
| 49 | public String MakeAppointment(Model model) {
|
---|
| 50 | List<Uslugi> uslugi = this.uslugiService.findAll();
|
---|
| 51 | List<Klienti> klienti = this.klientiService.listAll();
|
---|
| 52 | List<Termini> nerezTerm = this.terminiService.listAllNotReserved();
|
---|
| 53 |
|
---|
| 54 | model.addAttribute("uslugi", uslugi);
|
---|
| 55 | model.addAttribute("klienti", klienti);
|
---|
| 56 | model.addAttribute("nerezTerm",nerezTerm);
|
---|
| 57 | return "appointment_form.html";
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | @GetMapping("/appointment/{id}/edit")
|
---|
| 62 | public String showEdit(@PathVariable Integer id, Model model) {
|
---|
| 63 | Rezervacija rezervacija = this.rezervacijaService.findbyId(id);
|
---|
| 64 | List<Uslugi> uslugi = this.uslugiService.findAll();
|
---|
| 65 | List<Termini> nerezTerm = this.terminiService.listAllNotReserved();
|
---|
| 66 |
|
---|
| 67 | List<Uslugi> rezerviraniUslugi = this.rezervacijaUslugiService.listAllByBrRez(rezervacija);
|
---|
| 68 | model.addAttribute("rezerviraniUslugi",rezerviraniUslugi);
|
---|
| 69 | model.addAttribute("rezervacija",rezervacija);
|
---|
| 70 | model.addAttribute("uslugi", uslugi);
|
---|
| 71 | model.addAttribute("nerezTerm",nerezTerm);
|
---|
| 72 |
|
---|
| 73 | return "editAppointment.html";
|
---|
| 74 | }
|
---|
| 75 | @PostMapping("/makeAppointment")
|
---|
| 76 | public String create(@RequestParam List<String> uslugiIds,
|
---|
| 77 | @RequestParam Integer klientId,
|
---|
| 78 | @RequestParam Integer terminId
|
---|
| 79 | ) {
|
---|
| 80 | List<Uslugi> uslugi = this.uslugiService.findAllById(uslugiIds);
|
---|
| 81 | Klienti klient = this.klientiService.findById(klientId);
|
---|
| 82 | Rezervacija rezervacija = this.rezervacijaService.create(klientId,terminId,uslugi);
|
---|
| 83 | return "redirect:/appointment";
|
---|
| 84 | }
|
---|
| 85 | @PostMapping("/appointment/{id}")
|
---|
| 86 | public String update(@PathVariable Integer id,
|
---|
| 87 | @RequestParam List<String> uslugiIds,
|
---|
| 88 | @RequestParam Integer klientId,
|
---|
| 89 | @RequestParam Integer terminId) {
|
---|
| 90 |
|
---|
| 91 | this.rezervacijaService.update(id, uslugiIds, klientId,terminId);
|
---|
| 92 |
|
---|
| 93 | return "redirect:/appointment";
|
---|
| 94 | }
|
---|
| 95 | @PostMapping({"/appointment/{id}/delete"})
|
---|
| 96 | public String delete(@PathVariable Integer id) {
|
---|
| 97 |
|
---|
| 98 | this.rezervacijaService.delete(id);
|
---|
| 99 | return "redirect:/appointment";
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | @GetMapping("/payment")
|
---|
| 103 | public String showCreditCard() {
|
---|
| 104 | return "creditCard_form.html";
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | }
|
---|