feat:更新朋友圈功能

This commit is contained in:
2025-06-27 15:58:43 +08:00
parent 9cfbae7c69
commit eadf548a94
8 changed files with 93 additions and 6 deletions

View File

@@ -1,11 +1,13 @@
package com.cxx.food.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cxx.food.dao.MomentDao;
import com.cxx.food.dto.CommentDto;
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.mapper.CommentMapper;
import com.cxx.food.mapper.MomentImageMapper;
import com.cxx.food.mapper.MomentMapper;
import com.cxx.food.service.MomentService;
import com.cxx.framework.web.CustomException;
@@ -26,11 +28,18 @@ public class MomentServiceImpl implements MomentService {
@Resource
private CommentMapper commentMapper;
@Resource
private MomentImageMapper momentImageMapper;
@Override
public Boolean addMoment(MomentDto momentDto) {
Moment moment = new Moment();
BeanUtils.copyProperties(momentDto, moment);
return momentMapper.insert(moment) == 1;
momentMapper.insert(moment);
insertMomentImage(moment.getId(), momentDto.getImageList());
return Boolean.TRUE;
}
@Override
@@ -42,7 +51,18 @@ public class MomentServiceImpl implements MomentService {
Moment moment = new Moment();
BeanUtils.copyProperties(momentDto, moment);
moment.setId(id);
return momentMapper.updateById(moment) == 1;
momentMapper.updateById(moment);
deleteMomentImage(id);
insertMomentImage(id, momentDto.getImageList());
return Boolean.TRUE;
}
@Override
public Boolean deleteMoment(Long id) {
deleteMomentImage(id);
momentMapper.deleteById(id);
return Boolean.TRUE;
}
@Override
@@ -62,4 +82,14 @@ public class MomentServiceImpl implements MomentService {
comment.setMomentId(momentId);
return commentMapper.insert(comment) == 1;
}
private void deleteMomentImage(Long id) {
momentImageMapper.delete(Wrappers.lambdaQuery(MomentImage.class).eq(MomentImage::getMomentId, id));
}
private void insertMomentImage(Long momentId, List<String> imageList) {
if (!imageList.isEmpty()) {
momentDao.insertMomentImage(momentId, imageList);
}
}
}