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

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

location-form

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