package com.project.beautycenter.web; import com.project.beautycenter.model.Termini; import com.project.beautycenter.model.Vraboteni; 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.time.Instant; import java.util.List; @Controller public class TerminiController { private final TerminiService terminiService; private final RezervacijaService rezervacijaService; private final UslugiService uslugiService; private final RezervacijaUslugiService rezervacijaUslugiService; private final VraboteniService vraboteniService; public TerminiController(TerminiService terminiService, RezervacijaService rezervacijaService, UslugiService uslugiService, RezervacijaUslugiService rezervacijaUslugiService, VraboteniService vraboteniService) { this.terminiService = terminiService; this.rezervacijaService = rezervacijaService; this.uslugiService = uslugiService; this.rezervacijaUslugiService = rezervacijaUslugiService; this.vraboteniService = vraboteniService; } @GetMapping("/termini") public String listTermini(Model model) { List termini = this.terminiService.findAll(); List nerezTerm = this.terminiService.listAllNotReserved(); model.addAttribute("nerezTerm", nerezTerm); model.addAttribute("termini", termini); return "free_termini.html"; } @GetMapping("/termini/add") public String showAdd(Model model) { List vraboteni = this.vraboteniService.findAll(); model.addAttribute("vraboteni", vraboteni); return "termini_form.html"; } @GetMapping("/termini/{id}/edit") public String showEdit(@PathVariable Integer id, Model model) { Termini termin = this.terminiService.findbyId(id); List vraboteni = this.vraboteniService.findAll(); model.addAttribute("termin", termin); model.addAttribute("vraboteni", vraboteni); return "termini_form.html"; } @PostMapping("/termini") public String create(@RequestParam String pocetok, @RequestParam Integer vremetraenje, @RequestParam Integer vrabotenId) { this.terminiService.create(Instant.parse(pocetok.substring(0, pocetok.length() - 1).concat("+02:00")), vremetraenje, vrabotenId); return "redirect:/termini"; } @PostMapping("/termini/{id}") public String update(@PathVariable Integer id, @RequestParam String pocetok, @RequestParam Integer vremetraenje, @RequestParam Integer vrabotenId) { this.terminiService.update(id, Instant.parse(pocetok.substring(0, pocetok.length() - 1).concat("+02:00")), vremetraenje, vrabotenId); return "redirect:/termini"; } @PostMapping({"/termini/{id}/delete"}) public String delete(@PathVariable Integer id) { this.terminiService.delete(id); return "redirect:/termini"; } }