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.RegistriranParkirac;
|
---|
13 | import parkup.services.RegistriranParkiracService;
|
---|
14 |
|
---|
15 | @RestController
|
---|
16 | public class RegistriranParkiracController {
|
---|
17 | private final RegistriranParkiracService registriranParkiracService;
|
---|
18 |
|
---|
19 | @Autowired
|
---|
20 | public RegistriranParkiracController(RegistriranParkiracService registriranParkiracService) {
|
---|
21 | this.registriranParkiracService = registriranParkiracService;
|
---|
22 | }
|
---|
23 |
|
---|
24 | @GetMapping({"/registriranParkirac"})
|
---|
25 | public List<RegistriranParkirac> getAllRegistriraniParkiraci() {
|
---|
26 | return this.registriranParkiracService.getRegPark();
|
---|
27 | }
|
---|
28 |
|
---|
29 | @GetMapping({"/registriranParkirac/{regParkId}"})
|
---|
30 | public RegistriranParkirac getRegistriranParkirac(@PathVariable int regParkId) {
|
---|
31 | RegistriranParkirac regPark = this.registriranParkiracService.findById(regParkId);
|
---|
32 | if (regPark != null) {
|
---|
33 | return regPark;
|
---|
34 | } else {
|
---|
35 | throw new RuntimeException("User not found");
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | @PostMapping({"/registriranParkirac"})
|
---|
40 | public void addRegistriranParkirac(@RequestBody RegistriranParkirac regPark) {
|
---|
41 | this.registriranParkiracService.addRegPark(regPark);
|
---|
42 | }
|
---|
43 |
|
---|
44 | @PutMapping({"/registriranParkirac/{regParkId}"})
|
---|
45 | public void updateRegistriranParkirac(@PathVariable int regParkId, @RequestBody RegistriranParkirac regPark) {
|
---|
46 | this.registriranParkiracService.updateRegPark(regParkId, regPark.getName(), regPark.getSurname(), regPark.getMobile(), regPark.getEmail());
|
---|
47 | }
|
---|
48 |
|
---|
49 | @DeleteMapping({"/registriranParkirac/{regParkId}"})
|
---|
50 | public void deleteRegistriranParkirac(@PathVariable int regParkId) {
|
---|
51 | this.registriranParkiracService.deleteRegPark(regParkId);
|
---|
52 | }
|
---|
53 | } |
---|