use of org.collectiveone.modules.governance.CardLike in project CollectiveOneWebapp by CollectiveOne.
the class ModelService method setLikeToCard.
@Transactional
public PostResult setLikeToCard(UUID cardWrapperId, UUID authorId, boolean likeStatus) {
ModelCardWrapper card = modelCardWrapperRepository.findById(cardWrapperId);
AppUser author = appUserRepository.findByC1Id(authorId);
CardLike like = cardLikeRepository.findByCardWrapperIdAndAuthor_c1Id(cardWrapperId, authorId);
/* add the like*/
if (likeStatus == true) {
if (like == null) {
like = new CardLike();
like.setAuthor(author);
like.setCardWrapper(card);
cardLikeRepository.save(like);
} else {
/* nothing to do, the like is already registered */
}
} else {
if (like != null) {
cardLikeRepository.delete(like);
} else {
/* nothing to do, the like is already absent */
}
}
return new PostResult("success", "like status changed", null);
}
Aggregations