feat:增加分页查询朋友圈功能
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.cxx.food.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cxx.food.dto.*;
|
||||
import com.cxx.food.service.MomentService;
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
@@ -43,6 +44,13 @@ public class MomentController {
|
||||
return momentService.queryMomentList();
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询所有朋友圈")
|
||||
@GetMapping("/page")
|
||||
public IPage<MomentDto> queryMomentByPage(@RequestParam("currentPage") Integer currentPage,
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
return momentService.queryMomentByPage(currentPage, pageSize);
|
||||
}
|
||||
|
||||
@Operation(summary = "查询朋友圈")
|
||||
@GetMapping("/{id}")
|
||||
public @JsonView(ReadView.class) List<MomentDto> queryMomentById(@PathVariable("id") long id) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.cxx.food.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.cxx.food.dto.*;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -10,6 +12,8 @@ import java.util.List;
|
||||
public interface MomentDao {
|
||||
List<MomentDto> queryMomentList();
|
||||
|
||||
IPage<MomentDto> queryMomentByPage(Page<MomentDto> page);
|
||||
|
||||
List<MomentDto> queryMomentById(@Param("id") Long id);
|
||||
|
||||
void insertMomentImage(@Param("momentId") Long momentId,
|
||||
|
||||
41
src/main/java/com/cxx/food/dto/MomentPageDto.java
Normal file
41
src/main/java/com/cxx/food/dto/MomentPageDto.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.cxx.food.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class MomentPageDto {
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "姓名")
|
||||
private String username;
|
||||
|
||||
@Schema(description = "头像")
|
||||
private String avatar;
|
||||
|
||||
@Schema(description = "朋友圈内容")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "朋友圈图片")
|
||||
private List<String> imageList;
|
||||
|
||||
@Schema(description = "时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date date;
|
||||
|
||||
@Schema(description = "点赞用户")
|
||||
private List<Long> likeList;
|
||||
|
||||
@Schema(description = "评论内容")
|
||||
private List<CommentDto> commentList;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.cxx.food.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cxx.food.dto.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -14,6 +15,8 @@ public interface MomentService {
|
||||
|
||||
List<MomentDto> queryMomentList();
|
||||
|
||||
IPage<MomentDto> queryMomentByPage(int currentPage, int pageSize);
|
||||
|
||||
List<MomentDto> queryMomentById(Long id);
|
||||
|
||||
Boolean addComment(Long momentId, String content);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.cxx.food.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.cxx.food.constant.BizType;
|
||||
import com.cxx.food.dao.MomentDao;
|
||||
import com.cxx.food.dto.MomentDto;
|
||||
@@ -74,6 +76,12 @@ public class MomentServiceImpl implements MomentService {
|
||||
return momentDao.queryMomentList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<MomentDto> queryMomentByPage(int currentPage, int pageSize) {
|
||||
Page<MomentDto> page = new Page<>(currentPage, pageSize);
|
||||
return momentDao.queryMomentByPage(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MomentDto> queryMomentById(Long id) {
|
||||
return momentDao.queryMomentById(id);
|
||||
|
||||
@@ -18,6 +18,23 @@
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="momentPageResultMap" type="com.cxx.food.dto.MomentPageDto">
|
||||
<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="likeList" ofType="long"
|
||||
column="id" select="queryMomentLike">
|
||||
</collection>
|
||||
<collection property="commentList" ofType="com.cxx.food.dto.CommentDto"
|
||||
column="id" select="queryMomentComment">
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="commentResultMap" type="com.cxx.food.dto.CommentDto">
|
||||
<id property="id" column="id"/>
|
||||
<result property="username" column="username"/>
|
||||
@@ -56,6 +73,18 @@
|
||||
ORDER BY a.create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="queryMomentByPage" resultMap="momentPageResultMap">
|
||||
SELECT a.id AS id,
|
||||
b.id AS userId,
|
||||
b.username AS username,
|
||||
COALESCE(b.avatar, '') AS avatar,
|
||||
a.content AS content,
|
||||
a.create_time AS date
|
||||
FROM moment AS a
|
||||
LEFT JOIN user AS b ON a.create_by = b.id
|
||||
ORDER BY a.create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="queryMomentById" resultMap="momentResultMap">
|
||||
SELECT a.id AS id,
|
||||
b.id AS userId,
|
||||
|
||||
Reference in New Issue
Block a user