Last change
on this file since c064a42 was 57e58a3, checked in by ste08 <sjovanoska@…>, 4 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | package com.example.skychasemk.controller;
|
---|
2 |
|
---|
3 | import com.example.skychasemk.model.Destination;
|
---|
4 | import com.example.skychasemk.services.DestinationService;
|
---|
5 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
6 | import org.springframework.web.bind.annotation.*;
|
---|
7 |
|
---|
8 | import java.util.List;
|
---|
9 | import java.util.Optional;
|
---|
10 |
|
---|
11 | @RestController
|
---|
12 | @RequestMapping("/api/destinations")
|
---|
13 | public class DestinationController {
|
---|
14 |
|
---|
15 | @Autowired
|
---|
16 | private DestinationService destinationService;
|
---|
17 |
|
---|
18 | // Get all destinations
|
---|
19 | @GetMapping
|
---|
20 | public List<Destination> getAllDestinations() {
|
---|
21 | return destinationService.getAllDestinations();
|
---|
22 | }
|
---|
23 |
|
---|
24 | // Get destination by ID
|
---|
25 | @GetMapping("/{id}")
|
---|
26 | public Optional<Destination> getDestinationById(@PathVariable("id") Integer destinationID) {
|
---|
27 | return destinationService.getDestinationById(destinationID);
|
---|
28 | }
|
---|
29 |
|
---|
30 |
|
---|
31 | // Update an existing destination
|
---|
32 | @PutMapping("/{id}")
|
---|
33 | public Destination updateDestination(@PathVariable("id") Integer destinationID, @RequestBody Destination destination) {
|
---|
34 | return destinationService.updateDestination(destinationID, destination);
|
---|
35 | }
|
---|
36 |
|
---|
37 | // Delete a destination
|
---|
38 | @DeleteMapping("/{id}")
|
---|
39 | public void deleteDestination(@PathVariable("id") Integer destinationID) {
|
---|
40 | destinationService.deleteDestination(destinationID);
|
---|
41 | }
|
---|
42 | @GetMapping("/destinations")
|
---|
43 | public List<String> getDestinations() {
|
---|
44 | return destinationService.getAllCities();
|
---|
45 | }
|
---|
46 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.