1 | package finki.diplomska.tripplanner.web.rest;
|
---|
2 |
|
---|
3 | import finki.diplomska.tripplanner.models.Location;
|
---|
4 | import finki.diplomska.tripplanner.models.dto.PlannerLocationDto;
|
---|
5 | import finki.diplomska.tripplanner.service.LocationService;
|
---|
6 | import finki.diplomska.tripplanner.service.PlannerService;
|
---|
7 | import org.springframework.http.ResponseEntity;
|
---|
8 | import org.springframework.web.bind.annotation.*;
|
---|
9 |
|
---|
10 | import java.util.List;
|
---|
11 |
|
---|
12 | @RestController
|
---|
13 | @CrossOrigin(origins = "http://localhost:4200")
|
---|
14 | @RequestMapping(value = "/api")
|
---|
15 | public class LocationRestController {
|
---|
16 |
|
---|
17 | private final LocationService locationService;
|
---|
18 | private final PlannerService plannerService;
|
---|
19 |
|
---|
20 | public LocationRestController(LocationService locationService, PlannerService plannerService) {
|
---|
21 | this.locationService = locationService;
|
---|
22 | this.plannerService = plannerService;
|
---|
23 | }
|
---|
24 |
|
---|
25 | @GetMapping(value = "/locations")
|
---|
26 | public List<Location> findAllLocations(){
|
---|
27 | return this.locationService.findAll();
|
---|
28 | }
|
---|
29 |
|
---|
30 | @GetMapping(value = "/location/{id}")
|
---|
31 | public ResponseEntity<Location> findLocationById(@PathVariable Long id){
|
---|
32 | return this.locationService.findById(id)
|
---|
33 | .map(location -> ResponseEntity.ok().body(location))
|
---|
34 | .orElseGet(()-> ResponseEntity.notFound().build());
|
---|
35 | }
|
---|
36 |
|
---|
37 | @GetMapping(value = "/city/locations")
|
---|
38 | public List<Location> getAllLocationsFromCity(@RequestParam(required = false) Long cityId,
|
---|
39 | @RequestParam(required = false) Long companionId,
|
---|
40 | @RequestParam(required = false) Long lengthOfStay,
|
---|
41 | @RequestParam(required = false) String categoryIds) {
|
---|
42 | return this.locationService.findLocationsFromCityForm(cityId, companionId, lengthOfStay, categoryIds);
|
---|
43 |
|
---|
44 | }
|
---|
45 |
|
---|
46 | @GetMapping(value = "/region/locations")
|
---|
47 | public List<Location> getAllLocationsFromRegion(@RequestParam Long regionId,
|
---|
48 | @RequestParam Long companionId,
|
---|
49 | @RequestParam Long lengthOfStay,
|
---|
50 | @RequestParam String categoryIds){
|
---|
51 | return this.locationService.findLocationsFromRegionForm(regionId, companionId,lengthOfStay, categoryIds);
|
---|
52 | }
|
---|
53 |
|
---|
54 | @PostMapping(value = "/add-location")
|
---|
55 | public Location addLocationToPlanner(@RequestBody PlannerLocationDto plannerLocationDto){
|
---|
56 | return this.locationService.addLocationToPlanner(plannerLocationDto);
|
---|
57 | }
|
---|
58 |
|
---|
59 | @GetMapping(value = "/planner/locations")
|
---|
60 | public List<Location> getAllLocationsForPlanner (@RequestParam Long plannerId){
|
---|
61 | return this.locationService.getAllLocationsForPlanner(plannerId);
|
---|
62 | }
|
---|
63 |
|
---|
64 | @GetMapping(value = "weekend")
|
---|
65 | public List<Location> getWeekendGetaways(){
|
---|
66 | return this.locationService.getWeekendGetaways();
|
---|
67 | }
|
---|
68 |
|
---|
69 | @GetMapping(value = "villages")
|
---|
70 | public List<Location> getVillages(){
|
---|
71 | return this.locationService.getVillages();
|
---|
72 | }
|
---|
73 |
|
---|
74 | @GetMapping(value = "/planner/locationIds")
|
---|
75 | public List<Long> getAllLocationIdsForPlanner(@RequestParam Long plannerId){
|
---|
76 | return this.locationService.getAllLocationIdsForPlanner(plannerId);
|
---|
77 | }
|
---|
78 |
|
---|
79 | }
|
---|