source: src/main/java/com/project/beautycenter/web/KlientiController.java

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

Initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
1package com.project.beautycenter.web;
2
3import com.project.beautycenter.model.Klienti;
4import com.project.beautycenter.service.KlientiService;
5import org.springframework.stereotype.Controller;
6import org.springframework.ui.Model;
7import org.springframework.web.bind.annotation.GetMapping;
8import org.springframework.web.bind.annotation.PathVariable;
9import org.springframework.web.bind.annotation.PostMapping;
10import org.springframework.web.bind.annotation.RequestParam;
11
12import java.util.List;
13
14@Controller
15public 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}
Note: See TracBrowser for help on using the repository browser.