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.RegistrationServiceRP;
|
---|
10 | import parkup.data.enumarations.SessionStatus;
|
---|
11 | import parkup.entities.RegisteredUser;
|
---|
12 | import parkup.services.ParkingSessionService;
|
---|
13 | import parkup.services.RegisteredUserService;
|
---|
14 |
|
---|
15 | @RestController
|
---|
16 | public class RegisteredUserController {
|
---|
17 | private final RegisteredUserService registeredUserService;
|
---|
18 | private final RegistrationServiceRP registrationServiceRP;
|
---|
19 | private final ParkingSessionService parkingSessionService;
|
---|
20 |
|
---|
21 | @Autowired
|
---|
22 | public RegisteredUserController(RegisteredUserService registeredUserService, RegistrationServiceRP registrationServiceRP, ParkingSessionService parkingSessionService) {
|
---|
23 | this.registeredUserService = registeredUserService;
|
---|
24 | this.registrationServiceRP = registrationServiceRP;
|
---|
25 | this.parkingSessionService = parkingSessionService;
|
---|
26 | }
|
---|
27 |
|
---|
28 | @GetMapping({"/registriranParkirac"})
|
---|
29 | public List<RegisteredUser> getAllRegistriraniParkiraci() {
|
---|
30 | return this.registeredUserService.getRegPark();
|
---|
31 | }
|
---|
32 |
|
---|
33 | @GetMapping({"/registriranParkirac/{regParkId}"})
|
---|
34 | public RegisteredUser getRegistriranParkirac(@PathVariable int regParkId) {
|
---|
35 | RegisteredUser regPark = this.registeredUserService.findById(regParkId);
|
---|
36 | if (regPark != null) {
|
---|
37 | return regPark;
|
---|
38 | } else {
|
---|
39 | throw new RuntimeException("User not found");
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | @GetMapping({"registriranParkirac/{regParkId}/session"})
|
---|
44 | public SessionStatus getStatusOnParkirac(@PathVariable int regParkId){
|
---|
45 | return parkingSessionService.getStatusOfParkirac(regParkId);
|
---|
46 | }
|
---|
47 |
|
---|
48 | @PostMapping({"/registriranParkirac"})
|
---|
49 | public Optional<RegisteredUser> addRegistriranParkirac(@RequestBody RegisteredUser regPark) {
|
---|
50 | return this.registeredUserService.addRegPark(regPark);
|
---|
51 | }
|
---|
52 |
|
---|
53 | @PutMapping({"/registriranParkirac/{regParkId}"})
|
---|
54 | public RegisteredUser updateRegistriranParkirac(@PathVariable int regParkId, @RequestBody RegisteredUser regPark) {
|
---|
55 | return this.registeredUserService.updateRegPark(regParkId,regPark.getPassword(), regPark.getFirstName(), regPark.getLastName(), regPark.getMobile(), regPark.getEmail(),regPark.getPlates());
|
---|
56 | }
|
---|
57 |
|
---|
58 | @DeleteMapping({"/registriranParkirac/{regParkId}"})
|
---|
59 | public Optional<RegisteredUser> deleteRegistriranParkirac(@PathVariable int regParkId) {
|
---|
60 | return this.registeredUserService.deleteRegPark(regParkId);
|
---|
61 | }
|
---|
62 |
|
---|
63 | @PostMapping({"/registriranParkirac/registration"})
|
---|
64 | public String register(@RequestBody RegistrationRequest request){
|
---|
65 | return registrationServiceRP.register(request);
|
---|
66 | }
|
---|
67 |
|
---|
68 | @GetMapping(path = "/registriranParkirac/registration/confirm")
|
---|
69 | public String confirm(@RequestParam("token") String token) {
|
---|
70 | return registrationServiceRP.confirmToken(token);
|
---|
71 | }
|
---|
72 | } |
---|