source: sources/app/src/main/java/parkup/controllers/VrabotenController.java@ ce6ad22

Last change on this file since ce6ad22 was ce6ad22, checked in by DavidTrajkovski <davidtrajkovski11@…>, 3 years ago

v1 initial prototype

  • Property mode set to 100644
File size: 1.9 KB
Line 
1package parkup.controllers;
2
3import java.util.List;
4import org.springframework.beans.factory.annotation.Autowired;
5import org.springframework.web.bind.annotation.DeleteMapping;
6import org.springframework.web.bind.annotation.GetMapping;
7import org.springframework.web.bind.annotation.PathVariable;
8import org.springframework.web.bind.annotation.PostMapping;
9import org.springframework.web.bind.annotation.PutMapping;
10import org.springframework.web.bind.annotation.RequestBody;
11import org.springframework.web.bind.annotation.RestController;
12import parkup.entities.Vraboten;
13import parkup.services.VrabotenService;
14
15@RestController
16public 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}
Note: See TracBrowser for help on using the repository browser.