result = badRequest("Module does not exist");
}
else
{
User user = currentUser();
Rate rate = null;
if (user != null)
{
// user shouldn't be null because of @RoleHolderPresent
rate = CollectionUtils.filterFirst(user.rates,
new Filter<Rate>()
{
@Override
public boolean isAcceptable(Rate rate)
{
return rate.playModule.id.equals(module.id);
}
});
if (rate != null)
{
module.rating.subtract(rate);
}
else
{
rate = new Rate();
rate.playModule = module;
user.rates.add(rate);
}
rate.rating = ratingForm.rating;
module.rating.add(rate);