[6a3a178] | 1 | package finki.diplomska.tripplanner.web.rest;
|
---|
| 2 |
|
---|
| 3 | import finki.diplomska.tripplanner.models.Location;
|
---|
[ceaed42] | 4 | import finki.diplomska.tripplanner.models.dto.PlannerLocationDto;
|
---|
[6a3a178] | 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 |
|
---|
[188ee53] | 37 | @GetMapping(value = "/city/locations")
|
---|
| 38 | public List<Location> getAllLocationsFromCity(@RequestParam(required = false) Long cityId,
|
---|
[eed0bf8] | 39 | @RequestParam(required = false) Long companionId,
|
---|
| 40 | @RequestParam(required = false) Long lengthOfStay,
|
---|
| 41 | @RequestParam(required = false) String categoryIds) {
|
---|
[188ee53] | 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);
|
---|
[6a3a178] | 52 | }
|
---|
[ceaed42] | 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 | }
|
---|
[59329aa] | 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 | }
|
---|
[6a3a178] | 73 | }
|
---|