54 lines
1.5 KiB
Java
54 lines
1.5 KiB
Java
package com.cxx.food.service.impl;
|
|
|
|
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.mapper.CommentMapper;
|
|
import com.cxx.food.mapper.MomentMapper;
|
|
import com.cxx.food.service.MomentService;
|
|
import com.cxx.framework.web.CustomException;
|
|
import jakarta.annotation.Resource;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.List;
|
|
|
|
@Service
|
|
public class MomentServiceImpl implements MomentService {
|
|
@Resource
|
|
private MomentDao momentDao;
|
|
|
|
@Resource
|
|
private MomentMapper momentMapper;
|
|
|
|
@Resource
|
|
private CommentMapper commentMapper;
|
|
|
|
@Override
|
|
public Boolean addMoment(MomentDto momentDto) {
|
|
Moment moment = new Moment();
|
|
BeanUtils.copyProperties(momentDto, moment);
|
|
return momentMapper.insert(moment) == 1;
|
|
}
|
|
|
|
@Override
|
|
public List<MomentDto> queryMoment() {
|
|
// TODO 只能查询好友的朋友圈
|
|
return momentDao.queryMoment();
|
|
}
|
|
|
|
@Override
|
|
public Boolean addComment(Long momentId, CommentDto commentDto) {
|
|
if (momentMapper.selectById(momentId) == null) {
|
|
throw new CustomException("该朋友圈不存在");
|
|
}
|
|
|
|
Comment comment = new Comment();
|
|
BeanUtils.copyProperties(commentDto, comment);
|
|
comment.setMomentId(momentId);
|
|
return commentMapper.insert(comment) == 1;
|
|
}
|
|
}
|