CatalogController.java
1,122 bytes
| 1 | package com.tasteprint.catalog; |
|---|---|
| 2 | |
| 3 | import java.util.List; |
| 4 | |
| 5 | import org.springframework.web.bind.annotation.GetMapping; |
| 6 | import org.springframework.web.bind.annotation.PathVariable; |
| 7 | import org.springframework.web.bind.annotation.RequestMapping; |
| 8 | import org.springframework.web.bind.annotation.RequestParam; |
| 9 | import org.springframework.web.bind.annotation.RestController; |
| 10 | |
| 11 | @RestController |
| 12 | @RequestMapping("/api/v1/catalog") |
| 13 | class CatalogController { |
| 14 | |
| 15 | private final CatalogService catalog; |
| 16 | |
| 17 | CatalogController(CatalogService catalog) { |
| 18 | this.catalog = catalog; |
| 19 | } |
| 20 | |
| 21 | @GetMapping("/destinations") |
| 22 | List<DestinationSummary> destinations() { |
| 23 | return catalog.destinations(); |
| 24 | } |
| 25 | |
| 26 | @GetMapping("/destinations/{code}") |
| 27 | DestinationDetails destination(@PathVariable String code) { |
| 28 | return catalog.destination(code); |
| 29 | } |
| 30 | |
| 31 | @GetMapping("/dishes/{slug}") |
| 32 | DishView dish(@PathVariable String slug) { |
| 33 | return catalog.dish(slug); |
| 34 | } |
| 35 | |
| 36 | @GetMapping("/dishes") |
| 37 | List<DishView> search(@RequestParam(defaultValue = "") String query) { |
| 38 | return catalog.search(query); |
| 39 | } |
| 40 | } |
| 41 | |