Package com.springone.myrestaurants.domain

Examples of com.springone.myrestaurants.domain.Restaurant


    @Transactional
    @Test
    public void testAddRecommendation() {
      UserAccount user = userAccountRepo.findUserAccount(userId);
      Restaurant rest = restaurantRepository.findRestaurant(22L);
      user.rate(rest, 3, "Pretty Good");
      em.flush();
      UserAccount updatedUser = userAccountRepo.findUserAccount(userId);
      Assert.assertNotNull("should have found something" ,updatedUser);
      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


    }

    @Transactional
    @Test
    public void testFindRestaurant() {
      Restaurant r = repo.findRestaurant(1L);
      Assert.assertNotNull("should have found something" ,r);
      Assert.assertEquals("should have found the right one", "Boston Market", r.getName());
    }
View Full Code Here

 
  @RequestMapping(value = "/{id}/{userId}", params = "favorite", method = RequestMethod.PUT)
    public String addFavoriteRestaurant(@PathVariable("id") Long id,
                      @PathVariable("userId") Long userId,
                      Model model) {
    Restaurant restaurant = this.restaurantDao.findRestaurant(id);
    UserAccount account = this.userAccountDao.findUserAccount(userId);   
    account.getFavorites().add(restaurant);
    this.userAccountDao.persist(account);
        addDateTimeFormatPatterns(model);      
        model.addAttribute("useraccount", account);
View Full Code Here

    private EntityManager entityManager;

  @Transactional
  public Restaurant findRestaurant(Long id) {
    if (id == null) return null;
    final Restaurant rest = entityManager.find(Restaurant.class, id);
    if (rest != null) {
      rest.persist();
    }
    return rest;
    }
View Full Code Here

    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

    Iterable<Recommendation> recs = account.getRecommendations();
    //View expects a list with indexer access and properties that match those of the form bean.
    List<RecommendationFormBean> listRecs = new ArrayList<RecommendationFormBean>();
    for (Recommendation recommendation : recs) {
      RecommendationFormBean rfb = new RecommendationFormBean();
            final Restaurant restaurant = recommendation.getRestaurant();
            rfb.setComments(recommendation.getComment());
            rfb.setName(restaurant.getName());
      rfb.setRating(recommendation.getStars());   
      rfb.setId(recommendation.getRelationshipId());
            rfb.setRestaurantId(restaurant.getId());
      listRecs.add(rfb);
    }                       
    model.addAttribute("recommendations", listRecs);
        return "recommendations/list";
    }
View Full Code Here

    if (result.hasErrors()) {
      model.addAttribute("recommendation", recommendationFormBean);
      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());
View Full Code Here

  @RequestMapping(value = "/{restaurantId}/{userId}", params = "form", method = RequestMethod.GET)
    public String createForm(@PathVariable("restaurantId") Long restaurantId,
                @PathVariable("userId") Long userId,
                       Model model) {  
    RecommendationFormBean recBean = new RecommendationFormBean();
    Restaurant restaurant = this.restaurantRepository.findRestaurant(restaurantId);
    recBean.setRestaurantId(restaurantId);
    recBean.setName(restaurant.getName());
        model.addAttribute("recommendation", recBean);             
        //currentUserId is part of the implicit model due to spring security
       
        //model.addAttribute("userId", userId.toString());
        return "recommendations/create"; ///" + restaurantId + "/" + userId;
View Full Code Here

 
  @RequestMapping(value = "/{id}/{userId}", params = "favorite", method = RequestMethod.PUT)
    public String addFavoriteRestaurant(@PathVariable("id") Long id,
                      @PathVariable("userId") Long userId,
                      Model model) {
    Restaurant restaurant = this.restaurantRepository.findRestaurant(id);
    UserAccount account = this.userAccountRepository.findUserAccount(userId);   
    account.getFavorites().add(restaurant);
    this.userAccountRepository.persist(account);
        addDateTimeFormatPatterns(model);      
        model.addAttribute("useraccount", account);
View Full Code Here

    }

    @Transactional
    @Test
    public void testFindRestaurant() {
      Restaurant r = repo.findRestaurant(1L);
      Assert.assertNotNull("should have found something" ,r);
      Assert.assertEquals("should have found the right one", "Boston Market", r.getName());
    }
View Full Code Here

TOP

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

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.