Package com.springone.myrestaurants.domain

Examples of com.springone.myrestaurants.domain.Recommendation


      List<Recommendation> recommendations = new ArrayList<Recommendation>();
      for (Recommendation r : updatedUser.getRecommendations()) {
        recommendations.add(r);
      }
      Assert.assertEquals("user should now have correct number of recommendations", 1, recommendations.size());
      Recommendation r = recommendations.get(0);
      Assert.assertEquals("recommendation should have correct rating", 3, r.getStars());
      Assert.assertEquals("recommendation should have correct comment", "Pretty Good", r.getComment());
        final Restaurant restaurant = r.getRestaurant();
        Assert.assertEquals("recommendation should have correct restaurant id", new Long(22), restaurant.getId());
      Assert.assertEquals("recommendation should have correct restaurant name", "Subway Sandwiches & Salads", restaurant.getName());
    }
View Full Code Here


                 Model model) {
        if (result.hasErrors()) {
            model.addAttribute("recommendation", recommendationFormBean);
            return "recommendations/update";
        }
        Recommendation foundRec = findRecommendation(userId, recommendationFormBean.getId());
        foundRec.rate(recommendationFormBean.getRating(), recommendationFormBean.getComments())
        model.addAttribute("itemId", recommendationFormBean.getId());
        return "redirect:/recommendations/" + recommendationFormBean.getId();
    }
View Full Code Here

 
    @RequestMapping(value = "/{id}", params = "form", method = RequestMethod.GET)
    public String updateForm(@PathVariable("id") Long id,
                 @ModelAttribute("currentUserAccountId") Long userId,
                 Model model) {
      Recommendation foundRec = findRecommendation(userId, id);
      RecommendationFormBean recBean = new RecommendationFormBean();
      if (foundRec != null) {
        recBean.setComments(foundRec.getComment());  
        recBean.setId(foundRec.getRelationshipId());
        recBean.setRating(foundRec.getStars());          
        recBean.setName(foundRec.getRestaurant().getName());
        recBean.setRestaurantId(foundRec.getRestaurant().getId());
      }
        model.addAttribute("recommendation", recBean);
        model.addAttribute("itemId", recBean.getId());
        return "recommendations/update";
    }
View Full Code Here

    public String delete(@PathVariable("id") Long id,
                 @RequestParam(value = "page", required = false) Integer page,
               @RequestParam(value = "size", required = false) Integer size,
               @ModelAttribute("currentUserAccountId") Long userId,
               Model model) {
      Recommendation foundRec = findRecommendation(userId, id);
      if (foundRec != null) {
        if (foundRec.hasPersistentState()) {
          foundRec.getPersistentState().delete();
        }
      }
        model.addAttribute("page", (page == null) ? "1" : page.toString());
        model.addAttribute("size", (size == null) ? "10" : size.toString());
        return "redirect:/recommendations?page=" + ((page == null) ? "1" : page.toString()) + "&size=" + ((size == null) ? "10" : size.toString());
View Full Code Here

  @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public String show(@PathVariable("id") Long recommendationId,
               @ModelAttribute("currentUserAccountId") Long userId,
               Model model) {
   
    Recommendation foundRec = findRecommendation(userId, recommendationId);
    RecommendationFormBean bean = new RecommendationFormBean();
    if (foundRec != null) {
      bean.setComments(foundRec.getComment());
      bean.setRating(foundRec.getStars());
            bean.setId(foundRec.getRelationshipId());
            Restaurant r = foundRec.getRestaurant();
            bean.setName(r.getName());
            bean.setRestaurantId(r.getId());
    }
    model.addAttribute("recommendation", bean);
        return "recommendations/show";
View Full Code Here

  private Recommendation findRecommendation(Long userId,
      Long recommendationId) {
    UserAccount account = this.userAccountRepository.findUserAccount(userId);
    Iterable<Recommendation> recs = account.getRecommendations();
    Recommendation foundRec = null;
    for (Recommendation recommendation : recs) {
      if (recommendation.getRelationshipId().equals(recommendationId)) {
        foundRec = recommendation;
      }
    }
View Full Code Here

      return "recommendations/create";
    }
    long restaurantId = recommendationFormBean.getRestaurantId();
    Restaurant restaurant = this.restaurantRepository.findRestaurant(restaurantId);
    UserAccount account = this.userAccountRepository.findUserAccount(userId);
    Recommendation recommendation = account.rate(restaurant,
        recommendationFormBean.getRating(),
        recommendationFormBean.getComments());
    model.addAttribute("recommendationId", recommendation.getRelationshipId());
    return "redirect:/recommendations/" + recommendation.getRelationshipId();
  }
View Full Code Here

      List<Recommendation> recommendations = new ArrayList<Recommendation>();
      for (Recommendation r : updatedUser.getRecommendations()) {
        recommendations.add(r);
      }
      Assert.assertEquals("user should now have correct number of recommendations", 1, recommendations.size());
      Recommendation r = recommendations.get(0);
      Assert.assertEquals("recommendation should have correct rating", 3, r.getStars());
      Assert.assertEquals("recommendation should have correct comment", "Pretty Good", r.getComment());
      Assert.assertEquals("recommendation should have correct restaurant id", new Long(22), r.getRestaurant().getId());
      Assert.assertEquals("recommendation should have correct restaurant name", "Subway Sandwiches & Salads", r.getRestaurant().getName());
    }
View Full Code Here

TOP

Related Classes of com.springone.myrestaurants.domain.Recommendation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.