Skip to content

Commit

Permalink
feat: 一行判断likestatus
Browse files Browse the repository at this point in the history
  • Loading branch information
Aseubel committed Nov 28, 2024
1 parent 2ac6234 commit 8b54731
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Optional;

/**
* @author huangwenxing
Expand All @@ -27,7 +28,7 @@ public class LikeRepository implements ILikeRepository {
/**键过期时间500ms*/
private long expired = 500;
@Override
@Transactional
@Transactional(rollbackFor = Exception.class)
public void like(String fromId, String toId, boolean liked) {
/**更新点赞状态*/
Integer row = mapper.updateLiked(fromId, toId, liked);
Expand All @@ -53,11 +54,12 @@ public String getLikeValue(String fromId, String toId) {

@Override
public boolean queryLikedById(String fromId, String toId) {
Integer liked = mapper.queryLikedById(fromId, toId);
if(liked==null){
return false;
}
return liked == 1;
// Integer liked = mapper.queryLikedById(fromId, toId);
// if(liked==null){
// return false;
// }
// return liked == 1;
return Optional.ofNullable(mapper.queryLikedById(fromId, toId)).map(i -> i == 1).orElse(false);
}

@Override
Expand Down

0 comments on commit 8b54731

Please sign in to comment.