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

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

initial commit

  • Property mode set to 100644
File size: 2.1 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 @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}
Note: See TracBrowser for help on using the repository browser.