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