1 | package finki.diplomska.tripplanner.web.rest;
|
---|
2 |
|
---|
3 | import finki.diplomska.tripplanner.models.Location;
|
---|
4 | import finki.diplomska.tripplanner.service.LocationService;
|
---|
5 | import finki.diplomska.tripplanner.service.PlannerService;
|
---|
6 | import org.springframework.http.ResponseEntity;
|
---|
7 | import org.springframework.web.bind.annotation.*;
|
---|
8 |
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | @RestController
|
---|
12 | @CrossOrigin(origins = "http://localhost:4200")
|
---|
13 | @RequestMapping(value = "/api")
|
---|
14 | public class LocationRestController {
|
---|
15 |
|
---|
16 | private final LocationService locationService;
|
---|
17 | private final PlannerService plannerService;
|
---|
18 |
|
---|
19 | public LocationRestController(LocationService locationService, PlannerService plannerService) {
|
---|
20 | this.locationService = locationService;
|
---|
21 | this.plannerService = plannerService;
|
---|
22 | }
|
---|
23 |
|
---|
24 | @GetMapping(value = "/locations")
|
---|
25 | public List<Location> findAllLocations(){
|
---|
26 | return this.locationService.findAll();
|
---|
27 | }
|
---|
28 |
|
---|
29 | @GetMapping(value = "/location/{id}")
|
---|
30 | public ResponseEntity<Location> findLocationById(@PathVariable Long id){
|
---|
31 | return this.locationService.findById(id)
|
---|
32 | .map(location -> ResponseEntity.ok().body(location))
|
---|
33 | .orElseGet(()-> ResponseEntity.notFound().build());
|
---|
34 | }
|
---|
35 |
|
---|
36 | @GetMapping(value = "/city/locations")
|
---|
37 | public List<Location> getAllLocationsFromCity(@RequestParam(required = false) Long cityId,
|
---|
38 | @RequestParam(required = false) Long companionId,
|
---|
39 | @RequestParam(required = false) Long lengthOfStay,
|
---|
40 | @RequestParam(required = false) String categoryIds) {
|
---|
41 | return this.locationService.findLocationsFromCityForm(cityId, companionId, lengthOfStay, categoryIds);
|
---|
42 |
|
---|
43 | }
|
---|
44 |
|
---|
45 | @GetMapping(value = "/region/locations")
|
---|
46 | public List<Location> getAllLocationsFromRegion(@RequestParam(required = false) Long regionId,
|
---|
47 | @RequestParam(required = false) Long companionId,
|
---|
48 | @RequestParam(required = false) Long lengthOfStay,
|
---|
49 | @RequestParam(required = false) String categoryIds){
|
---|
50 | return this.locationService.findLocationsFromRegionForm(regionId, companionId,lengthOfStay, categoryIds);
|
---|
51 | }
|
---|
52 | }
|
---|