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

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

adding photos

  • Property mode set to 100644
File size: 3.1 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.http.ResponseEntity;
8import org.springframework.web.bind.annotation.*;
9
10import java.util.List;
11
12@RestController
13@CrossOrigin(origins = "http://localhost:4200")
14@RequestMapping(value = "/api")
15public 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(required = false) Long regionId,
48 @RequestParam(required = false) Long companionId,
49 @RequestParam(required = false) Long lengthOfStay,
50 @RequestParam(required = false) String categoryIds){
51 return this.locationService.findLocationsFromRegionForm(regionId, companionId,lengthOfStay, categoryIds);
52 }
53
54 @PutMapping(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}
Note: See TracBrowser for help on using the repository browser.