1 | package com.example.baziproekt.web;
|
---|
2 |
|
---|
3 |
|
---|
4 | import com.example.baziproekt.model.Korisnici;
|
---|
5 | import com.example.baziproekt.model.Roles;
|
---|
6 | import com.example.baziproekt.service.KorisniciService;
|
---|
7 | import org.springframework.stereotype.Controller;
|
---|
8 | import org.springframework.ui.Model;
|
---|
9 | import org.springframework.web.bind.annotation.*;
|
---|
10 |
|
---|
11 | import java.util.List;
|
---|
12 |
|
---|
13 | @Controller
|
---|
14 | @RequestMapping("/korisnici")
|
---|
15 | public class KorisniciController {
|
---|
16 | private final KorisniciService service;
|
---|
17 |
|
---|
18 | public KorisniciController(KorisniciService service) {
|
---|
19 | this.service = service;
|
---|
20 | }
|
---|
21 | @GetMapping
|
---|
22 | public String getKorisnici( Model model)
|
---|
23 | {
|
---|
24 | List<Korisnici> korisnicis=service.findAll();
|
---|
25 | model.addAttribute("korisnici",korisnicis);
|
---|
26 | return "korisnici";
|
---|
27 | }
|
---|
28 |
|
---|
29 | @GetMapping("/{ime}/edit")
|
---|
30 | public String showEdit(@PathVariable String ime,Model model)
|
---|
31 | {
|
---|
32 | Korisnici k=service.findByIme(ime);
|
---|
33 | model.addAttribute("korisnik",k);
|
---|
34 | model.addAttribute("ulogi",Roles.values());
|
---|
35 |
|
---|
36 | return "edit_form";
|
---|
37 |
|
---|
38 | }
|
---|
39 | @PostMapping("/{korisnicko_ime}")
|
---|
40 | public String update(@PathVariable String korisnicko_ime, @RequestParam String lozinka,
|
---|
41 | @RequestParam String email,@RequestParam String telefonski_broj)
|
---|
42 | {
|
---|
43 |
|
---|
44 | service.update(korisnicko_ime,lozinka,email,telefonski_broj);
|
---|
45 | return "redirect:/korisnici";
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 | }
|
---|