1 | package com.project.beautycenter.web;
|
---|
2 |
|
---|
3 | import com.project.beautycenter.model.Klienti;
|
---|
4 | import com.project.beautycenter.service.KlientiService;
|
---|
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 KlientiController {
|
---|
16 | private final KlientiService klientiService;
|
---|
17 |
|
---|
18 | public KlientiController(KlientiService klientiService) {
|
---|
19 |
|
---|
20 | this.klientiService = klientiService;
|
---|
21 | }
|
---|
22 |
|
---|
23 | @GetMapping("/clients")
|
---|
24 | public String showClients(Model model) {
|
---|
25 | List<Klienti> klienti = this.klientiService.listAll();
|
---|
26 |
|
---|
27 | model.addAttribute("klienti", klienti);
|
---|
28 |
|
---|
29 | return "clients.html";
|
---|
30 | }
|
---|
31 |
|
---|
32 | @GetMapping("/clients/{id}/edit")
|
---|
33 | public String showEdit(@PathVariable Integer id, Model model) {
|
---|
34 | Klienti klient = this.klientiService.findById(id);
|
---|
35 |
|
---|
36 | model.addAttribute("klient", klient);
|
---|
37 | return "edit_form.html";
|
---|
38 | }
|
---|
39 |
|
---|
40 | @PostMapping("/clients/{id}")
|
---|
41 | public String update(@PathVariable Integer id,
|
---|
42 | @RequestParam String ime,
|
---|
43 | @RequestParam String prezime,
|
---|
44 | @RequestParam String telBr,
|
---|
45 | @RequestParam String email) {
|
---|
46 | this.klientiService.update(id, ime, prezime, telBr, email);
|
---|
47 | return "redirect:/clients";
|
---|
48 | }
|
---|
49 |
|
---|
50 | } |
---|