|
3 | 3 | import java.util.Optional; |
4 | 4 |
|
5 | 5 | import javax.validation.Valid; |
| 6 | +import java.util.stream.Collectors; |
6 | 7 |
|
7 | 8 | import org.couchbase.quickstart.springdata.models.Airport; |
8 | 9 | import org.couchbase.quickstart.springdata.services.AirportService; |
| 10 | +import org.couchbase.quickstart.springdata.models.Route; |
9 | 11 | import org.springframework.dao.DataRetrievalFailureException; |
10 | 12 | import org.springframework.data.domain.Page; |
11 | 13 | import org.springframework.data.domain.PageRequest; |
12 | 14 | import org.springframework.http.HttpStatus; |
13 | 15 | import org.springframework.http.ResponseEntity; |
| 16 | + |
14 | 17 | import org.springframework.web.bind.annotation.DeleteMapping; |
15 | 18 | import org.springframework.web.bind.annotation.GetMapping; |
16 | 19 | import org.springframework.web.bind.annotation.PathVariable; |
@@ -123,13 +126,15 @@ public ResponseEntity<Page<Airport>> listAirports(@RequestParam(defaultValue = " |
123 | 126 | } |
124 | 127 |
|
125 | 128 | @GetMapping("/direct-connections") |
126 | | - public ResponseEntity<Page<Airport>> listDirectConnections( |
127 | | - @RequestParam String airport, |
| 129 | + public ResponseEntity<Page<String>> listDirectConnections( |
| 130 | + @RequestParam String airportCode, |
128 | 131 | @RequestParam(defaultValue = "0") int page, |
129 | 132 | @RequestParam(defaultValue = "10") int size) { |
130 | 133 | try { |
131 | | - Page<Airport> airports = airportService.getDirectConnections(airport, PageRequest.of(page, size)); |
132 | | - return new ResponseEntity<>(airports, HttpStatus.OK); |
| 134 | + Page<Route> airports = airportService.getDirectConnections(airportCode, PageRequest.of(page, size)); |
| 135 | + Page<String> directConnections = airports.map(Route::getDestinationAirport); |
| 136 | + return new ResponseEntity<>(directConnections, HttpStatus.OK); |
| 137 | + |
133 | 138 | } catch (Exception e) { |
134 | 139 | log.error(INTERNAL_SERVER_ERROR, e); |
135 | 140 | return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); |
|
0 commit comments