feat:新增点赞接口
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
package com.cxx.food.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.cxx.food.dao.MomentDao;
|
||||
import com.cxx.food.dto.MomentDto;
|
||||
import com.cxx.food.entity.Comment;
|
||||
import com.cxx.food.entity.Moment;
|
||||
import com.cxx.food.entity.MomentImage;
|
||||
import com.cxx.food.entity.*;
|
||||
import com.cxx.food.mapper.CommentMapper;
|
||||
import com.cxx.food.mapper.MomentLikeMapper;
|
||||
import com.cxx.food.mapper.MomentImageMapper;
|
||||
import com.cxx.food.mapper.MomentMapper;
|
||||
import com.cxx.food.service.MomentService;
|
||||
@@ -28,6 +29,9 @@ public class MomentServiceImpl implements MomentService {
|
||||
@Resource
|
||||
private CommentMapper commentMapper;
|
||||
|
||||
@Resource
|
||||
private MomentLikeMapper momentLikeMapper;
|
||||
|
||||
@Resource
|
||||
private MomentImageMapper momentImageMapper;
|
||||
|
||||
@@ -83,6 +87,41 @@ public class MomentServiceImpl implements MomentService {
|
||||
return commentMapper.insert(comment) == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean addLike(Long momentId) {
|
||||
LambdaQueryWrapper<MomentLike> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(MomentLike::getMomentId, momentId).eq(MomentLike::getCreateBy, StpUtil.getLoginIdAsString());
|
||||
MomentLike like = momentLikeMapper.selectOne(queryWrapper);
|
||||
|
||||
if (like != null) {
|
||||
if (like.getIsDelete() == 0) {
|
||||
throw new CustomException("已经点赞了");
|
||||
} else {
|
||||
like.setIsDelete(0);
|
||||
return momentLikeMapper.updateById(like) == 1;
|
||||
}
|
||||
}
|
||||
|
||||
MomentLike newLike = new MomentLike();
|
||||
newLike.setMomentId(momentId);
|
||||
newLike.setIsDelete(0);
|
||||
return momentLikeMapper.insert(newLike) == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteLike(Long momentId) {
|
||||
LambdaQueryWrapper<MomentLike> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(MomentLike::getMomentId, momentId).eq(MomentLike::getCreateBy, StpUtil.getLoginIdAsString());
|
||||
MomentLike like = momentLikeMapper.selectOne(queryWrapper);
|
||||
|
||||
if (like == null ) {
|
||||
throw new CustomException("该朋友圈不存在");
|
||||
}
|
||||
|
||||
like.setIsDelete(1);
|
||||
return momentLikeMapper.updateById(like) == 1;
|
||||
}
|
||||
|
||||
private void deleteMomentImage(Long id) {
|
||||
momentImageMapper.delete(Wrappers.lambdaQuery(MomentImage.class).eq(MomentImage::getMomentId, id));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user