source: src/main/java/com/project/beautycenter/web/TerminiController.java@ 850b344

Last change on this file since 850b344 was 850b344, checked in by Tamara Simikj <tamara.simic12@…>, 2 years ago

Initial commit

  • Property mode set to 100644
File size: 3.3 KB
Line 
1package com.project.beautycenter.web;
2
3import com.project.beautycenter.model.Termini;
4import com.project.beautycenter.model.Vraboteni;
5import com.project.beautycenter.service.*;
6import org.springframework.stereotype.Controller;
7import org.springframework.ui.Model;
8import org.springframework.web.bind.annotation.GetMapping;
9import org.springframework.web.bind.annotation.PathVariable;
10import org.springframework.web.bind.annotation.PostMapping;
11import org.springframework.web.bind.annotation.RequestParam;
12
13import java.time.Instant;
14import java.util.List;
15
16@Controller
17public class TerminiController {
18 private final TerminiService terminiService;
19 private final RezervacijaService rezervacijaService;
20 private final UslugiService uslugiService;
21 private final RezervacijaUslugiService rezervacijaUslugiService;
22 private final VraboteniService vraboteniService;
23
24 public TerminiController(TerminiService terminiService, RezervacijaService rezervacijaService, UslugiService uslugiService, RezervacijaUslugiService rezervacijaUslugiService, VraboteniService vraboteniService) {
25 this.terminiService = terminiService;
26 this.rezervacijaService = rezervacijaService;
27 this.uslugiService = uslugiService;
28 this.rezervacijaUslugiService = rezervacijaUslugiService;
29 this.vraboteniService = vraboteniService;
30 }
31
32 @GetMapping("/termini")
33 public String listTermini(Model model) {
34 List<Termini> termini = this.terminiService.findAll();
35 List<Termini> nerezTerm = this.terminiService.listAllNotReserved();
36
37 model.addAttribute("nerezTerm", nerezTerm);
38 model.addAttribute("termini", termini);
39
40 return "free_termini.html";
41 }
42
43 @GetMapping("/termini/add")
44 public String showAdd(Model model) {
45 List<Vraboteni> vraboteni = this.vraboteniService.findAll();
46 model.addAttribute("vraboteni", vraboteni);
47 return "termini_form.html";
48 }
49
50 @GetMapping("/termini/{id}/edit")
51 public String showEdit(@PathVariable Integer id, Model model) {
52 Termini termin = this.terminiService.findbyId(id);
53 List<Vraboteni> vraboteni = this.vraboteniService.findAll();
54
55 model.addAttribute("termin", termin);
56 model.addAttribute("vraboteni", vraboteni);
57
58 return "termini_form.html";
59 }
60
61 @PostMapping("/termini")
62 public String create(@RequestParam String pocetok,
63 @RequestParam Integer vremetraenje,
64 @RequestParam Integer vrabotenId) {
65
66 this.terminiService.create(Instant.parse(pocetok.substring(0, pocetok.length() - 1).concat("+02:00")),
67 vremetraenje, vrabotenId);
68 return "redirect:/termini";
69 }
70
71 @PostMapping("/termini/{id}")
72 public String update(@PathVariable Integer id,
73 @RequestParam String pocetok,
74 @RequestParam Integer vremetraenje,
75 @RequestParam Integer vrabotenId) {
76 this.terminiService.update(id, Instant.parse(pocetok.substring(0, pocetok.length() - 1).concat("+02:00")),
77 vremetraenje, vrabotenId);
78 return "redirect:/termini";
79 }
80
81 @PostMapping({"/termini/{id}/delete"})
82 public String delete(@PathVariable Integer id) {
83 this.terminiService.delete(id);
84 return "redirect:/termini";
85 }
86
87}
Note: See TracBrowser for help on using the repository browser.