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

Last change on this file since 97fbc67 was 97fbc67, checked in by andrejTavchioski <andrej.tavchioski@…>, 3 years ago

fixed deleteVraboten and deleteRegistriranParkirac

  • Property mode set to 100644
File size: 2.6 KB
Line 
1package parkup.controllers;
2
3import java.util.List;
4import java.util.Optional;
5
6import org.springframework.beans.factory.annotation.Autowired;
7import org.springframework.web.bind.annotation.*;
8import parkup.configs.RegistrationRequest;
9import parkup.configs.RegistrationServiceW;
10import parkup.entities.Vraboten;
11import parkup.services.VrabotenService;
12import parkup.data.VrabotenDemo;
13
14@RestController
15public class VrabotenController {
16 private final VrabotenService vrabotenService;
17 private final RegistrationServiceW registrationServiceW;
18
19 @Autowired
20 public VrabotenController(VrabotenService vrabotenService, RegistrationServiceW registrationServiceW) {
21 this.vrabotenService = vrabotenService;
22 this.registrationServiceW = registrationServiceW;
23 }
24
25 @GetMapping({"/vraboten"})
26 public List<Vraboten> getAllVraboten() {
27 return this.vrabotenService.getVraboteni();
28 }
29
30 @GetMapping({"/vraboten/{vrabotenId}"})
31 public Vraboten getVraboten(@PathVariable int vrabotenId) {
32 Vraboten vraboten = this.vrabotenService.findById(vrabotenId);
33 if (vraboten != null) {
34 return vraboten;
35 } else {
36 throw new RuntimeException("Vraboten not found");
37 }
38 }
39
40 @GetMapping({"/vraboten/vrabotenDemo"})
41 public List<VrabotenDemo> getVraboteniDemos(){
42 return this.vrabotenService.getAllVraboteniDemos();
43 }
44
45 @PostMapping({"/vraboten"})
46 public Optional<Vraboten> addVraboten(@RequestBody Vraboten vraboten) {
47 return this.vrabotenService.addVraboten(vraboten);
48 }
49
50 @PostMapping({"/vraboten/{vrabotenId}"})
51 public void lockVraboten(@PathVariable int vrabotenId) {
52 this.vrabotenService.lockVrabotenAcc(vrabotenId);
53 }
54
55 @PutMapping({"/vraboten/{vrabotenId}"})
56 public Vraboten updateVraboten(@PathVariable int vrabotenId, @RequestBody Vraboten vraboten) {
57 return this.vrabotenService.updateVraboten(vrabotenId, vraboten.getFirstName(), vraboten.getLastName(),
58 vraboten.getMobile(), vraboten.getEmail(), vraboten.getStatus());
59 }
60
61 @DeleteMapping({"/vraboten/{vrabotenId}"})
62 public Optional<Vraboten> deleteVraboten(@PathVariable int vrabotenId) {
63 return this.vrabotenService.deleteVraboten(vrabotenId);
64 }
65
66 @PostMapping({"/vraboten/registration"})
67 public String register(@RequestBody RegistrationRequest request){
68 return registrationServiceW.register(request);
69 }
70
71 @GetMapping(path = "/vraboten/registration/confirm")
72 public String confirm(@RequestParam("token") String token) {
73 return registrationServiceW.confirmToken(token);
74 }
75}
Note: See TracBrowser for help on using the repository browser.