예제 #1
0
  public int getRating() {
    HttpSession session = FacesUtil.getSession();
    User user = (User) session.getAttribute("user");

    Rating userRating = getUserRating(user);
    if (userRating != null) {
      this.rating = userRating.getRating();
    }

    return this.rating;
  }
예제 #2
0
  public Rating getUserRating(User user) {
    this.recipe = service.getById(this.recipe.getId());
    List<Rating> ratingList = this.recipe.getRatingList();
    if (ratingList != null && !ratingList.isEmpty()) {

      for (Rating rating : ratingList) {
        User rater = rating.getUserId();
        if (rater.getId() == user.getId()) {
          return rating;
        }
      }
    }

    return null;
  }
예제 #3
0
  public void onrate(RateEvent rateEvent) {

    HttpSession session = FacesUtil.getSession();
    User user = (User) session.getAttribute("user");

    Rating userRating = getUserRating(user);

    int score = ((Integer) rateEvent.getRating()).intValue();
    Rating rate = new Rating();
    rate.setRating(score);
    rate.setRecipe(recipe);
    rate.setUserId(user);

    if (userRating == null) {
      serviceRating.create(rate);
    } else {
      rate.setId(userRating.getId());
      serviceRating.update(rate);
    }
  }