Search in sources :

Example 1 with CardLike

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);
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) AppUser(org.collectiveone.modules.users.AppUser) CardLike(org.collectiveone.modules.governance.CardLike) Transactional(javax.transaction.Transactional)

Aggregations

Transactional (javax.transaction.Transactional)1 PostResult (org.collectiveone.common.dto.PostResult)1 CardLike (org.collectiveone.modules.governance.CardLike)1 AppUser (org.collectiveone.modules.users.AppUser)1