source: trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/LocationRestController.java@ 8d391a1

Last change on this file since 8d391a1 was 8d391a1, checked in by Ema <ema_spirova@…>, 3 years ago

disabling to add location if it already exists in the planner

  • Property mode set to 100644
File size: 3.4 KB
Line 
1package finki.diplomska.tripplanner.web.rest;
2
3import finki.diplomska.tripplanner.models.Location;
4import finki.diplomska.tripplanner.models.dto.PlannerLocationDto;
5import finki.diplomska.tripplanner.service.LocationService;
6import finki.diplomska.tripplanner.service.PlannerService;
7import org.springframework.data.repository.query.Param;
8import org.springframework.http.ResponseEntity;
9import org.springframework.web.bind.annotation.*;
10
11import java.util.List;
12
13@RestController
14@CrossOrigin(origins = "http://localhost:4200")
15@RequestMapping(value = "/api")
16public 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}
Note: See TracBrowser for help on using the repository browser.