source: sources/app/src/main/java/parkup/controllers/GuestController.java@ 9ff45d6

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

v1 initial prototype

  • Property mode set to 100644
File size: 1.5 KB
Line 
1package parkup.controllers;
2
3import java.util.List;
4import java.util.UUID;
5import org.springframework.beans.factory.annotation.Autowired;
6import org.springframework.web.bind.annotation.DeleteMapping;
7import org.springframework.web.bind.annotation.GetMapping;
8import org.springframework.web.bind.annotation.PathVariable;
9import org.springframework.web.bind.annotation.PostMapping;
10import org.springframework.web.bind.annotation.RequestBody;
11import org.springframework.web.bind.annotation.RestController;
12import parkup.entities.Guest;
13import parkup.services.GuestService;
14
15@RestController
16public class GuestController {
17 private final GuestService guestService;
18
19 @Autowired
20 public GuestController(GuestService guestService) {
21 this.guestService = guestService;
22 }
23
24 @GetMapping({"/guest"})
25 public List<Guest> getAllGuest() {
26 return this.guestService.getGuests();
27 }
28
29 @GetMapping({"/guest/{guestId}"})
30 public Guest getGuest(@PathVariable int guestId) {
31 Guest guest = this.guestService.findById(guestId);
32 if (guest != null) {
33 return guest;
34 } else {
35 throw new RuntimeException("Guest not found");
36 }
37 }
38
39 @PostMapping({"/guest"})
40 public void addGuest(@RequestBody Guest guest) {
41 this.guestService.addGuest(guest);
42 }
43
44 @DeleteMapping({"/guest/{guestId}"})
45 public void deleteGuest(@PathVariable int guestId) {
46 this.guestService.deleteGuest(guestId);
47 }
48}
Note: See TracBrowser for help on using the repository browser.