source: trip-planner/src/main/java/finki/diplomska/tripplanner/web/HomeController.java

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

initial commit

  • Property mode set to 100644
File size: 3.2 KB
Line 
1package finki.diplomska.tripplanner.web;
2
3import finki.diplomska.tripplanner.models.*;
4import finki.diplomska.tripplanner.service.*;
5import org.springframework.stereotype.Controller;
6import org.springframework.ui.Model;
7import org.springframework.web.bind.annotation.*;
8
9import java.util.List;
10import java.util.Optional;
11
12@Controller
13@RequestMapping(value = "/old")
14public class HomeController {
15
16 private final CityService cityService;
17 private final CountryService countryService;
18 private final CategoryService categoryService;
19 private final CompanionService companionService;
20 private final LocationService locationService;
21 private final RegionService regionService;
22 private final PlannerService plannerService;
23
24 public HomeController(CityService cityService, CountryService countryService,
25 CategoryService categoryService, CompanionService companionService,
26 LocationService locationService, RegionService regionService, PlannerService plannerService) {
27 this.cityService = cityService;
28 this.countryService = countryService;
29 this.categoryService = categoryService;
30 this.companionService = companionService;
31 this.locationService = locationService;
32 this.regionService = regionService;
33 this.plannerService = plannerService;
34 }
35
36 @GetMapping
37 public String homepage(Model model){
38 List<City> cities = this.cityService.findAll();
39 List<Country> countries = this.countryService.findAll();
40 List<Category> categories = this.categoryService.findAll();
41 List<Companion> companions = this.companionService.findAll();
42 List<Region> regions = this.regionService.findAll();
43 model.addAttribute("cities", cities);
44 model.addAttribute("countries", countries);
45 model.addAttribute("categories",categories);
46 model.addAttribute("companions",companions);
47 model.addAttribute("regions",regions);
48 return "homepage";
49 }
50
51 @PostMapping(value = "/trip/locations")
52 public String allLocations(Model model, @RequestParam(required = false) String ime,
53 @RequestParam(required = false) String pridruzba,
54 @RequestParam(required = false) String region,
55 @RequestParam(required = false) List<String> categories,
56 @RequestParam(required = false) int numberOfDays) {
57 List<Location> countryLocations = this.locationService.scheduleLocations(ime, pridruzba, region, categories, numberOfDays);
58 if(ime.equals("Macedonia")){
59 model.addAttribute("countryLocations", countryLocations);
60 return "trip-locations-country";
61 }else
62 model.addAttribute("imgUtil", new ImageUtil());
63 model.addAttribute("countryLocations", countryLocations);
64 return "trip-locations";
65 }
66
67 @GetMapping(value = "/trip/locations/{id}")
68 public String seeDetailsAboutLocation(@PathVariable Long id, Model model){
69 Optional<Location> location = this.locationService.findById(id);
70 model.addAttribute("location", location);
71 return "location";
72 }
73
74}
Note: See TracBrowser for help on using the repository browser.