Rev | Line | |
---|
[57e58a3] | 1 | package com.example.skychasemk.controller;
|
---|
| 2 |
|
---|
| 3 | import com.example.skychasemk.model.Airport;
|
---|
| 4 | import com.example.skychasemk.services.AirportService;
|
---|
| 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/airports")
|
---|
| 13 | public class AirportController {
|
---|
| 14 |
|
---|
| 15 | @Autowired
|
---|
| 16 | private AirportService airportService;
|
---|
| 17 |
|
---|
| 18 | // Get all airports
|
---|
| 19 | @GetMapping
|
---|
| 20 | public List<Airport> getAllAirports() {
|
---|
| 21 | return airportService.getAllAirports();
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | // Get airport by ID
|
---|
| 25 | @GetMapping("/{id}")
|
---|
| 26 | public Optional<Airport> getAirportById(@PathVariable("id") Integer airportID) {
|
---|
| 27 | return airportService.getAirportById(airportID);
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | // Create a new airport
|
---|
| 31 | @PostMapping
|
---|
| 32 | public Airport createAirport(@RequestBody Airport airport) {
|
---|
| 33 | return airportService.saveAirport(airport);
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | // Update an existing airport
|
---|
| 37 | @PutMapping("/{id}")
|
---|
| 38 | public Airport updateAirport(@PathVariable("id") Integer airportID, @RequestBody Airport airport) {
|
---|
| 39 | return airportService.updateAirport(airportID, airport);
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | // Delete an airport
|
---|
| 43 | @DeleteMapping("/{id}")
|
---|
| 44 | public void deleteAirport(@PathVariable("id") Integer airportID) {
|
---|
| 45 | airportService.deleteAirport(airportID);
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.