1 | package parkup.controllers;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 | import java.util.Optional;
|
---|
5 |
|
---|
6 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
7 | import org.springframework.web.bind.annotation.*;
|
---|
8 | import parkup.configs.RegistrationRequest;
|
---|
9 | import parkup.configs.RegistrationServiceW;
|
---|
10 | import parkup.entities.Vraboten;
|
---|
11 | import parkup.services.VrabotenService;
|
---|
12 | import parkup.data.VrabotenDemo;
|
---|
13 |
|
---|
14 | @RestController
|
---|
15 | public 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 | } |
---|