[ce6ad22] | 1 | package parkup.controllers;
|
---|
| 2 |
|
---|
| 3 | import java.util.List;
|
---|
| 4 | import java.util.UUID;
|
---|
| 5 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
| 6 | import org.springframework.web.bind.annotation.DeleteMapping;
|
---|
| 7 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
| 8 | import org.springframework.web.bind.annotation.PathVariable;
|
---|
| 9 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
| 10 | import org.springframework.web.bind.annotation.RequestBody;
|
---|
| 11 | import org.springframework.web.bind.annotation.RestController;
|
---|
| 12 | import parkup.entities.Guest;
|
---|
| 13 | import parkup.services.GuestService;
|
---|
| 14 |
|
---|
| 15 | @RestController
|
---|
| 16 | public 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"})
|
---|
[bc20307] | 40 | public Guest addGuest(@RequestBody Guest guest) {
|
---|
| 41 | Guest guestToReturn = this.guestService.addGuest(guest);
|
---|
| 42 | return guestToReturn;
|
---|
[ce6ad22] | 43 | }
|
---|
| 44 |
|
---|
| 45 | @DeleteMapping({"/guest/{guestId}"})
|
---|
| 46 | public void deleteGuest(@PathVariable int guestId) {
|
---|
| 47 | this.guestService.deleteGuest(guestId);
|
---|
| 48 | }
|
---|
| 49 | }
|
---|