1 | package parkup.controllers;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
5 | import org.springframework.web.bind.annotation.DeleteMapping;
|
---|
6 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
7 | import org.springframework.web.bind.annotation.PathVariable;
|
---|
8 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
9 | import org.springframework.web.bind.annotation.PutMapping;
|
---|
10 | import org.springframework.web.bind.annotation.RequestBody;
|
---|
11 | import org.springframework.web.bind.annotation.RestController;
|
---|
12 | import parkup.entities.Vraboten;
|
---|
13 | import parkup.services.VrabotenService;
|
---|
14 |
|
---|
15 | @RestController
|
---|
16 | public class VrabotenController {
|
---|
17 | private final VrabotenService vrabotenService;
|
---|
18 |
|
---|
19 | @Autowired
|
---|
20 | public VrabotenController(VrabotenService vrabotenService) {
|
---|
21 | this.vrabotenService = vrabotenService;
|
---|
22 | }
|
---|
23 |
|
---|
24 | @GetMapping({"/vraboten"})
|
---|
25 | public List<Vraboten> getAllVraboten() {
|
---|
26 | return this.vrabotenService.getVraboteni();
|
---|
27 | }
|
---|
28 |
|
---|
29 | @GetMapping({"/vraboten/{vrabotenId}"})
|
---|
30 | public Vraboten getVraboten(@PathVariable int vrabotenId) {
|
---|
31 | Vraboten vraboten = this.vrabotenService.findById(vrabotenId);
|
---|
32 | if (vraboten != null) {
|
---|
33 | return vraboten;
|
---|
34 | } else {
|
---|
35 | throw new RuntimeException("Vraboten not found");
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | @PostMapping({"/vraboten"})
|
---|
40 | public void addVraboten(@RequestBody Vraboten vraboten) {
|
---|
41 | this.vrabotenService.addVraboten(vraboten);
|
---|
42 | }
|
---|
43 |
|
---|
44 | @PutMapping({"/vraboten/{vrabotenId}"})
|
---|
45 | public void updateVraboten(@PathVariable int vrabotenId, @RequestBody Vraboten vraboten) {
|
---|
46 | this.vrabotenService.updateVraboten(vrabotenId, vraboten.getFirstName(), vraboten.getLastName(), vraboten.getMobile(), vraboten.getEmail());
|
---|
47 | }
|
---|
48 |
|
---|
49 | @DeleteMapping({"/vraboten/{vrabotenId}"})
|
---|
50 | public void deleteVraboten(@PathVariable int vrabotenId) {
|
---|
51 | this.vrabotenService.deleteVraboten(vrabotenId);
|
---|
52 | }
|
---|
53 | } |
---|