feat:更新朋友圈功能
This commit is contained in:
@@ -31,6 +31,12 @@ public class MomentController {
|
||||
return momentService.updateMoment(id, momentDto);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除朋友圈")
|
||||
@DeleteMapping("/{id}")
|
||||
public Boolean deleteMoment(@PathVariable("id") long id) {
|
||||
return momentService.deleteMoment(id);
|
||||
}
|
||||
|
||||
@Operation(summary = "查询朋友圈")
|
||||
@GetMapping("")
|
||||
public @JsonView(ReadView.class) List<MomentDto> queryMoment() {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.cxx.food.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cxx.food.dto.*;
|
||||
import com.cxx.food.vo.FoodQueryVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -11,4 +9,7 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface MomentDao {
|
||||
List<MomentDto> queryMoment();
|
||||
|
||||
void insertMomentImage(@Param("momentId") Long momentId,
|
||||
@Param("list") List<String> imageFiles);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@ public class MomentDto {
|
||||
@JsonView(ReadView.class)
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户id")
|
||||
@JsonView(ReadView.class)
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "姓名")
|
||||
@JsonView(ReadView.class)
|
||||
private String username;
|
||||
@@ -30,6 +34,9 @@ public class MomentDto {
|
||||
@NotBlank(message = "内容不能为空")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "朋友圈图片")
|
||||
private List<String> imageList;
|
||||
|
||||
@Schema(description = "时间")
|
||||
@JsonView(ReadView.class)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
|
||||
15
src/main/java/com/cxx/food/entity/MomentImage.java
Normal file
15
src/main/java/com/cxx/food/entity/MomentImage.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.cxx.food.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName("moment_image")
|
||||
public class MomentImage {
|
||||
@TableField("moment_id")
|
||||
private Long momentId;
|
||||
|
||||
@TableField("image_url")
|
||||
private String imageUrl;
|
||||
}
|
||||
9
src/main/java/com/cxx/food/mapper/MomentImageMapper.java
Normal file
9
src/main/java/com/cxx/food/mapper/MomentImageMapper.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.cxx.food.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.cxx.food.entity.MomentImage;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface MomentImageMapper extends BaseMapper<MomentImage> {
|
||||
}
|
||||
@@ -10,6 +10,8 @@ public interface MomentService {
|
||||
|
||||
Boolean updateMoment(Long id, MomentDto momentDto);
|
||||
|
||||
Boolean deleteMoment(Long id);
|
||||
|
||||
List<MomentDto> queryMoment();
|
||||
|
||||
Boolean addComment(Long momentId, String content);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,13 @@
|
||||
<mapper namespace="com.cxx.food.dao.MomentDao">
|
||||
<resultMap id="momentResultMap" type="com.cxx.food.dto.MomentDto">
|
||||
<id property="id" column="id"/>
|
||||
<result property="userId" column="userId"/>
|
||||
<result property="username" column="username"/>
|
||||
<result property="avatar" column="avatar"/>
|
||||
<result property="content" column="content"/>
|
||||
<result property="date" column="date"/>
|
||||
<collection property="imageList" ofType="java.lang.String"
|
||||
column="id" select="queryMomentImage"/>
|
||||
<collection property="commentList" ofType="com.cxx.food.dto.CommentDto"
|
||||
column="id" select="queryComment">
|
||||
</collection>
|
||||
@@ -32,7 +35,8 @@
|
||||
</select>
|
||||
|
||||
<select id="queryMoment" resultMap="momentResultMap">
|
||||
SELECT a.id AS id,
|
||||
SELECT a.id AS id,
|
||||
b.id AS userId,
|
||||
b.username AS username,
|
||||
b.avatar AS avatar,
|
||||
a.content AS content,
|
||||
@@ -41,4 +45,17 @@
|
||||
LEFT JOIN user AS b ON a.create_by = b.id
|
||||
ORDER BY a.update_time DESC
|
||||
</select>
|
||||
|
||||
<select id="queryMomentImage" resultType="java.lang.String">
|
||||
SELECT image_url AS imageUrl
|
||||
FROM moment_image
|
||||
WHERE moment_id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertMomentImage">
|
||||
INSERT INTO moment_image (moment_id, image_url) VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{momentId}, #{item})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user