[6a3a178] | 1 | package finki.diplomska.tripplanner.web.rest;
|
---|
| 2 |
|
---|
| 3 | import finki.diplomska.tripplanner.models.Location;
|
---|
| 4 | import finki.diplomska.tripplanner.service.LocationService;
|
---|
| 5 | import finki.diplomska.tripplanner.service.PlannerService;
|
---|
| 6 | import org.springframework.http.ResponseEntity;
|
---|
| 7 | import org.springframework.web.bind.annotation.*;
|
---|
| 8 |
|
---|
| 9 | import java.util.List;
|
---|
| 10 |
|
---|
| 11 | @RestController
|
---|
| 12 | @CrossOrigin(origins = "http://localhost:4200")
|
---|
| 13 | @RequestMapping(value = "/api")
|
---|
| 14 | public 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 | @PostMapping(value = "/trip/locations")
|
---|
| 37 | public List<Location> allLocationsAfterSubmittedForm(@RequestParam(required = false) String locName,
|
---|
| 38 | @RequestParam(required = false) String companion,
|
---|
| 39 | @RequestParam(required = false) String region,
|
---|
| 40 | @RequestParam(required = false) List<String> categories,
|
---|
| 41 | @RequestParam(required = false) int numberOfDays) {
|
---|
| 42 | List<Location> generatedLocations = this.locationService.scheduleLocations(locName, companion, region, categories, numberOfDays);
|
---|
| 43 | if(locName.equals("Macedonia")){
|
---|
| 44 | return generatedLocations;
|
---|
| 45 | }else{
|
---|
| 46 | return generatedLocations;
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 | }
|
---|