MoonSeokPyo / Papaya_nlpApp

nlpApp, PAPAYA
HomePage
0 stars 0 forks source link

[기능] SearchRestaurant #02 #2

Open akaneblue opened 2 weeks ago

akaneblue commented 2 weeks ago

PageController

    @GetMapping("/search/boundary") // 검색결과 처리(현재 사용자 위치와 그 주위 음식점들의 데이터를 페이지에 넘김)
    public String searchRestaurants(@RequestParam String address, Model model) {
        try {
            List<RestaurantDTO> restaurants = restaurantService.getNearbyRestaurants(address);
            Location location = geocodingService.getCoordinates(address);
            restaurants = restaurantService.sortRByScore(restaurants);
            model.addAttribute("restaurants", restaurants);
            model.addAttribute("location", location);

            if (restaurants.isEmpty())
                model.addAttribute("errorMessage", "주위의 음식점을 찾을 수 없습니다.");
        } catch (Exception e) {
            model.addAttribute("errorMessage", "주위의 음식점을 찾을 수 없습니다.");
        }
        return "result";
    }

    @GetMapping("/search/location") // 검색결과처리(특정 동네 이름을 검색하면 주소에 그 동네 이름이 들어있는 음식점들의 데이터만 넘김)
    public String searchRestaurantsByLocation(@RequestParam String address, Model model) {
        try {
            List<RestaurantDTO> restaurants = restaurantService.getRestaurantByLocation(address);
            Location location = geocodingService.getCoordinates(address);
            restaurants = restaurantService.sortRByScore(restaurants);
            model.addAttribute("restaurants", restaurants);
            model.addAttribute("location", location);

            if (restaurants.isEmpty())
                model.addAttribute("errorMessage", "동네의 맛집을 찾을 수 없습니다.");
        } catch (Exception e) {
            model.addAttribute("errorMessage", "동네의 맛집을 찾을 수 없습니다.");
        }
        return "result";
    }
    @GetMapping("/search/restaurant") // 검색을 통한 음식점 상세정보페이지 연결
    public ModelAndView searchRestaurant(@RequestParam String name) {
        List<RestaurantDTO> restaurants = restaurantService.searchRestaurantByName(name);
        ModelAndView mv = new ModelAndView();
        if (restaurants.size() == 1) {
            Restaurant restaurant = restaurantService.getRestaurant(name);
            List<Review> reviews = reviewService.viewReview(restaurant.getId());

            mv.setViewName("restaurantDetail");
            mv.addObject("restaurant", restaurant);
            mv.addObject("reviews", reviews);
        } else {
            try {
                restaurants = restaurantService.sortRByScore(restaurants);
                Location location = geocodingService.getCoordinates("서울");
                mv.setViewName("result");
                mv.addObject("restaurants",restaurants);
                mv.addObject("location",location);
            } catch (Exception e) {
                mv.addObject(e);
            }

        }
        return mv;
    }