diff --git a/src/main/java/top/peng/answerbi/controller/PostController.java b/src/main/java/top/peng/answerbi/controller/PostController.java
deleted file mode 100644
index 849bacf..0000000
--- a/src/main/java/top/peng/answerbi/controller/PostController.java
+++ /dev/null
@@ -1,250 +0,0 @@
-package top.peng.answerbi.controller;
-
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.google.gson.Gson;
-import java.util.List;
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.BeanUtils;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import top.peng.answerbi.annotation.AuthCheck;
-import top.peng.answerbi.common.CommonResponse;
-import top.peng.answerbi.common.DeleteRequest;
-import top.peng.answerbi.common.ErrorCode;
-import top.peng.answerbi.common.ResultUtils;
-import top.peng.answerbi.constant.UserConstant;
-import top.peng.answerbi.exception.BusinessException;
-import top.peng.answerbi.exception.ThrowUtils;
-import top.peng.answerbi.model.dto.post.PostAddRequest;
-import top.peng.answerbi.model.dto.post.PostEditRequest;
-import top.peng.answerbi.model.dto.post.PostQueryRequest;
-import top.peng.answerbi.model.dto.post.PostUpdateRequest;
-import top.peng.answerbi.model.entity.Post;
-import top.peng.answerbi.model.entity.User;
-import top.peng.answerbi.model.vo.PostVO;
-import top.peng.answerbi.service.PostService;
-import top.peng.answerbi.service.UserService;
-
-/**
- * 帖子接口
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@RestController
-@RequestMapping("/post")
-@Slf4j
-public class PostController {
-
- @Resource
- private PostService postService;
-
- @Resource
- private UserService userService;
-
- private final static Gson GSON = new Gson();
-
- // region 增删改查
-
- /**
- * 创建
- *
- * @param postAddRequest
- * @param request
- * @return
- */
- @PostMapping("/add")
- public CommonResponse addPost(@RequestBody PostAddRequest postAddRequest, HttpServletRequest request) {
- if (postAddRequest == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- Post post = new Post();
- BeanUtils.copyProperties(postAddRequest, post);
- List tags = postAddRequest.getTags();
- if (tags != null) {
- post.setTags(GSON.toJson(tags));
- }
- postService.validPost(post, true);
- User loginUser = userService.getLoginUser(request);
- post.setUserId(loginUser.getId());
- post.setFavourNum(0);
- post.setThumbNum(0);
- boolean result = postService.save(post);
- ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
- long newPostId = post.getId();
- return ResultUtils.success(newPostId);
- }
-
- /**
- * 删除
- *
- * @param deleteRequest
- * @param request
- * @return
- */
- @PostMapping("/delete")
- public CommonResponse deletePost(@RequestBody
- DeleteRequest deleteRequest, HttpServletRequest request) {
- if (deleteRequest == null || deleteRequest.getId() <= 0) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- User user = userService.getLoginUser(request);
- long id = deleteRequest.getId();
- // 判断是否存在
- Post oldPost = postService.getById(id);
- ThrowUtils.throwIf(oldPost == null, ErrorCode.NOT_FOUND_ERROR);
- // 仅本人或管理员可删除
- if (!oldPost.getUserId().equals(user.getId()) && !userService.isAdmin(request)) {
- throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
- }
- boolean b = postService.removeById(id);
- return ResultUtils.success(b);
- }
-
- /**
- * 更新(仅管理员)
- *
- * @param postUpdateRequest
- * @return
- */
- @PostMapping("/update")
- @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
- public CommonResponse updatePost(@RequestBody PostUpdateRequest postUpdateRequest) {
- if (postUpdateRequest == null || postUpdateRequest.getId() <= 0) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- Post post = new Post();
- BeanUtils.copyProperties(postUpdateRequest, post);
- List tags = postUpdateRequest.getTags();
- if (tags != null) {
- post.setTags(GSON.toJson(tags));
- }
- // 参数校验
- postService.validPost(post, false);
- long id = postUpdateRequest.getId();
- // 判断是否存在
- Post oldPost = postService.getById(id);
- ThrowUtils.throwIf(oldPost == null, ErrorCode.NOT_FOUND_ERROR);
- boolean result = postService.updateById(post);
- return ResultUtils.success(result);
- }
-
- /**
- * 根据 id 获取
- *
- * @param id
- * @return
- */
- @GetMapping("/get/vo")
- public CommonResponse getPostVOById(long id, HttpServletRequest request) {
- if (id <= 0) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- Post post = postService.getById(id);
- if (post == null) {
- throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
- }
- return ResultUtils.success(postService.getPostVO(post, request));
- }
-
- /**
- * 分页获取列表(封装类)
- *
- * @param postQueryRequest
- * @param request
- * @return
- */
- @PostMapping("/list/page/vo")
- public CommonResponse> listPostVOByPage(@RequestBody PostQueryRequest postQueryRequest,
- HttpServletRequest request) {
- long current = postQueryRequest.getCurrent();
- long size = postQueryRequest.getPageSize();
- // 限制爬虫
- ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR);
- Page postPage = postService.page(new Page<>(current, size),
- postService.getQueryWrapper(postQueryRequest));
- return ResultUtils.success(postService.getPostVOPage(postPage, request));
- }
-
- /**
- * 分页获取当前用户创建的资源列表
- *
- * @param postQueryRequest
- * @param request
- * @return
- */
- @PostMapping("/my/list/page/vo")
- public CommonResponse> listMyPostVOByPage(@RequestBody PostQueryRequest postQueryRequest,
- HttpServletRequest request) {
- if (postQueryRequest == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- User loginUser = userService.getLoginUser(request);
- postQueryRequest.setUserId(loginUser.getId());
- long current = postQueryRequest.getCurrent();
- long size = postQueryRequest.getPageSize();
- // 限制爬虫
- ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR);
- Page postPage = postService.page(new Page<>(current, size),
- postService.getQueryWrapper(postQueryRequest));
- return ResultUtils.success(postService.getPostVOPage(postPage, request));
- }
-
- // endregion
-
- /**
- * 分页搜索(从 ES 查询,封装类)
- *
- * @param postQueryRequest
- * @param request
- * @return
- */
- @PostMapping("/search/page/vo")
- public CommonResponse> searchPostVOByPage(@RequestBody PostQueryRequest postQueryRequest,
- HttpServletRequest request) {
- long size = postQueryRequest.getPageSize();
- // 限制爬虫
- ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR);
- Page postPage = postService.searchFromEs(postQueryRequest);
- return ResultUtils.success(postService.getPostVOPage(postPage, request));
- }
-
- /**
- * 编辑(用户)
- *
- * @param postEditRequest
- * @param request
- * @return
- */
- @PostMapping("/edit")
- public CommonResponse editPost(@RequestBody PostEditRequest postEditRequest, HttpServletRequest request) {
- if (postEditRequest == null || postEditRequest.getId() <= 0) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- Post post = new Post();
- BeanUtils.copyProperties(postEditRequest, post);
- List tags = postEditRequest.getTags();
- if (tags != null) {
- post.setTags(GSON.toJson(tags));
- }
- // 参数校验
- postService.validPost(post, false);
- User loginUser = userService.getLoginUser(request);
- long id = postEditRequest.getId();
- // 判断是否存在
- Post oldPost = postService.getById(id);
- ThrowUtils.throwIf(oldPost == null, ErrorCode.NOT_FOUND_ERROR);
- // 仅本人或管理员可编辑
- if (!oldPost.getUserId().equals(loginUser.getId()) && !userService.isAdmin(loginUser)) {
- throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
- }
- boolean result = postService.updateById(post);
- return ResultUtils.success(result);
- }
-
-}
diff --git a/src/main/java/top/peng/answerbi/controller/PostFavourController.java b/src/main/java/top/peng/answerbi/controller/PostFavourController.java
deleted file mode 100644
index 98016d9..0000000
--- a/src/main/java/top/peng/answerbi/controller/PostFavourController.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package top.peng.answerbi.controller;
-
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import top.peng.answerbi.common.CommonResponse;
-import top.peng.answerbi.common.ErrorCode;
-import top.peng.answerbi.common.ResultUtils;
-import top.peng.answerbi.exception.BusinessException;
-import top.peng.answerbi.exception.ThrowUtils;
-import top.peng.answerbi.model.dto.post.PostQueryRequest;
-import top.peng.answerbi.model.dto.postfavour.PostFavourAddRequest;
-import top.peng.answerbi.model.dto.postfavour.PostFavourQueryRequest;
-import top.peng.answerbi.model.entity.Post;
-import top.peng.answerbi.model.entity.User;
-import top.peng.answerbi.model.vo.PostVO;
-import top.peng.answerbi.service.PostFavourService;
-import top.peng.answerbi.service.PostService;
-import top.peng.answerbi.service.UserService;
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * 帖子收藏接口
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@RestController
-@RequestMapping("/post_favour")
-@Slf4j
-public class PostFavourController {
-
- @Resource
- private PostFavourService postFavourService;
-
- @Resource
- private PostService postService;
-
- @Resource
- private UserService userService;
-
- /**
- * 收藏 / 取消收藏
- *
- * @param postFavourAddRequest
- * @param request
- * @return resultNum 收藏变化数
- */
- @PostMapping("/")
- public CommonResponse doPostFavour(@RequestBody PostFavourAddRequest postFavourAddRequest,
- HttpServletRequest request) {
- if (postFavourAddRequest == null || postFavourAddRequest.getPostId() <= 0) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- // 登录才能操作
- final User loginUser = userService.getLoginUser(request);
- long postId = postFavourAddRequest.getPostId();
- int result = postFavourService.doPostFavour(postId, loginUser);
- return ResultUtils.success(result);
- }
-
- /**
- * 获取我收藏的帖子列表
- *
- * @param postQueryRequest
- * @param request
- */
- @PostMapping("/my/list/page")
- public CommonResponse> listMyFavourPostByPage(@RequestBody PostQueryRequest postQueryRequest,
- HttpServletRequest request) {
- if (postQueryRequest == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- User loginUser = userService.getLoginUser(request);
- long current = postQueryRequest.getCurrent();
- long size = postQueryRequest.getPageSize();
- // 限制爬虫
- ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR);
- Page postPage = postFavourService.listFavourPostByPage(new Page<>(current, size),
- postService.getQueryWrapper(postQueryRequest), loginUser.getId());
- return ResultUtils.success(postService.getPostVOPage(postPage, request));
- }
-
- /**
- * 获取用户收藏的帖子列表
- *
- * @param postFavourQueryRequest
- * @param request
- */
- @PostMapping("/list/page")
- public CommonResponse> listFavourPostByPage(@RequestBody PostFavourQueryRequest postFavourQueryRequest,
- HttpServletRequest request) {
- if (postFavourQueryRequest == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- long current = postFavourQueryRequest.getCurrent();
- long size = postFavourQueryRequest.getPageSize();
- Long userId = postFavourQueryRequest.getUserId();
- // 限制爬虫
- ThrowUtils.throwIf(size > 20 || userId == null, ErrorCode.PARAMS_ERROR);
- Page postPage = postFavourService.listFavourPostByPage(new Page<>(current, size),
- postService.getQueryWrapper(postFavourQueryRequest.getPostQueryRequest()), userId);
- return ResultUtils.success(postService.getPostVOPage(postPage, request));
- }
-}
diff --git a/src/main/java/top/peng/answerbi/controller/PostThumbController.java b/src/main/java/top/peng/answerbi/controller/PostThumbController.java
deleted file mode 100644
index 9db4b14..0000000
--- a/src/main/java/top/peng/answerbi/controller/PostThumbController.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package top.peng.answerbi.controller;
-
-import top.peng.answerbi.common.CommonResponse;
-import top.peng.answerbi.common.ErrorCode;
-import top.peng.answerbi.common.ResultUtils;
-import top.peng.answerbi.exception.BusinessException;
-import top.peng.answerbi.model.dto.postthumb.PostThumbAddRequest;
-import top.peng.answerbi.model.entity.User;
-import top.peng.answerbi.service.PostThumbService;
-import top.peng.answerbi.service.UserService;
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * 帖子点赞接口
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@RestController
-@RequestMapping("/post_thumb")
-@Slf4j
-public class PostThumbController {
-
- @Resource
- private PostThumbService postThumbService;
-
- @Resource
- private UserService userService;
-
- /**
- * 点赞 / 取消点赞
- *
- * @param postThumbAddRequest
- * @param request
- * @return resultNum 本次点赞变化数
- */
- @PostMapping("/")
- public CommonResponse doThumb(@RequestBody PostThumbAddRequest postThumbAddRequest,
- HttpServletRequest request) {
- if (postThumbAddRequest == null || postThumbAddRequest.getPostId() <= 0) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- // 登录才能点赞
- final User loginUser = userService.getLoginUser(request);
- long postId = postThumbAddRequest.getPostId();
- int result = postThumbService.doPostThumb(postId, loginUser);
- return ResultUtils.success(result);
- }
-
-}
diff --git a/src/main/java/top/peng/answerbi/esdao/PostEsDao.java b/src/main/java/top/peng/answerbi/esdao/PostEsDao.java
deleted file mode 100644
index ceff698..0000000
--- a/src/main/java/top/peng/answerbi/esdao/PostEsDao.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package top.peng.answerbi.esdao;
-
-import top.peng.answerbi.model.dto.post.PostEsDTO;
-import java.util.List;
-import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
-
-/**
- * 帖子 ES 操作
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-public interface PostEsDao extends ElasticsearchRepository {
-
- List findByUserId(Long userId);
-}
\ No newline at end of file
diff --git a/src/main/java/top/peng/answerbi/job/cycle/IncSyncPostToEs.java b/src/main/java/top/peng/answerbi/job/cycle/IncSyncPostToEs.java
deleted file mode 100644
index 9edbb10..0000000
--- a/src/main/java/top/peng/answerbi/job/cycle/IncSyncPostToEs.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package top.peng.answerbi.job.cycle;
-
-import top.peng.answerbi.esdao.PostEsDao;
-import top.peng.answerbi.mapper.PostMapper;
-import top.peng.answerbi.model.dto.post.PostEsDTO;
-import top.peng.answerbi.model.entity.Post;
-import java.util.Date;
-import java.util.List;
-import java.util.stream.Collectors;
-import javax.annotation.Resource;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.CollectionUtils;
-import org.springframework.scheduling.annotation.Scheduled;
-
-/**
- * 增量同步帖子到 es
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-// todo 取消注释开启任务
-//@Component
-@Slf4j
-public class IncSyncPostToEs {
-
- @Resource
- private PostMapper postMapper;
-
- @Resource
- private PostEsDao postEsDao;
-
- /**
- * 每分钟执行一次
- */
- @Scheduled(fixedRate = 60 * 1000)
- public void run() {
- // 查询近 5 分钟内的数据
- Date fiveMinutesAgoDate = new Date(new Date().getTime() - 5 * 60 * 1000L);
- List postList = postMapper.listPostWithDelete(fiveMinutesAgoDate);
- if (CollectionUtils.isEmpty(postList)) {
- log.info("no inc post");
- return;
- }
- List postEsDTOList = postList.stream()
- .map(PostEsDTO::objToDto)
- .collect(Collectors.toList());
- final int pageSize = 500;
- int total = postEsDTOList.size();
- log.info("IncSyncPostToEs start, total {}", total);
- for (int i = 0; i < total; i += pageSize) {
- int end = Math.min(i + pageSize, total);
- log.info("sync from {} to {}", i, end);
- postEsDao.saveAll(postEsDTOList.subList(i, end));
- }
- log.info("IncSyncPostToEs end, total {}", total);
- }
-}
diff --git a/src/main/java/top/peng/answerbi/job/once/FullSyncPostToEs.java b/src/main/java/top/peng/answerbi/job/once/FullSyncPostToEs.java
deleted file mode 100644
index 8665b1a..0000000
--- a/src/main/java/top/peng/answerbi/job/once/FullSyncPostToEs.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package top.peng.answerbi.job.once;
-
-import top.peng.answerbi.esdao.PostEsDao;
-import top.peng.answerbi.model.dto.post.PostEsDTO;
-import top.peng.answerbi.model.entity.Post;
-import top.peng.answerbi.service.PostService;
-import java.util.List;
-import java.util.stream.Collectors;
-import javax.annotation.Resource;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.CollectionUtils;
-import org.springframework.boot.CommandLineRunner;
-
-/**
- * 全量同步帖子到 es
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-// todo 取消注释开启任务
-//@Component
-@Slf4j
-public class FullSyncPostToEs implements CommandLineRunner {
-
- @Resource
- private PostService postService;
-
- @Resource
- private PostEsDao postEsDao;
-
- @Override
- public void run(String... args) {
- List postList = postService.list();
- if (CollectionUtils.isEmpty(postList)) {
- return;
- }
- List postEsDTOList = postList.stream().map(PostEsDTO::objToDto).collect(Collectors.toList());
- final int pageSize = 500;
- int total = postEsDTOList.size();
- log.info("FullSyncPostToEs start, total {}", total);
- for (int i = 0; i < total; i += pageSize) {
- int end = Math.min(i + pageSize, total);
- log.info("sync from {} to {}", i, end);
- postEsDao.saveAll(postEsDTOList.subList(i, end));
- }
- log.info("FullSyncPostToEs end, total {}", total);
- }
-}
diff --git a/src/main/java/top/peng/answerbi/mapper/PostFavourMapper.java b/src/main/java/top/peng/answerbi/mapper/PostFavourMapper.java
deleted file mode 100644
index 6cceba5..0000000
--- a/src/main/java/top/peng/answerbi/mapper/PostFavourMapper.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package top.peng.answerbi.mapper;
-
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.core.toolkit.Constants;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import top.peng.answerbi.model.entity.Post;
-import top.peng.answerbi.model.entity.PostFavour;
-import org.apache.ibatis.annotations.Param;
-
-/**
- * 帖子收藏数据库操作
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-public interface PostFavourMapper extends BaseMapper {
-
- /**
- * 分页查询收藏帖子列表
- *
- * @param page
- * @param queryWrapper
- * @param favourUserId
- * @return
- */
- Page listFavourPostByPage(IPage page, @Param(Constants.WRAPPER) Wrapper queryWrapper,
- long favourUserId);
-
-}
-
-
-
-
diff --git a/src/main/java/top/peng/answerbi/mapper/PostMapper.java b/src/main/java/top/peng/answerbi/mapper/PostMapper.java
deleted file mode 100644
index 39ebb70..0000000
--- a/src/main/java/top/peng/answerbi/mapper/PostMapper.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package top.peng.answerbi.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import top.peng.answerbi.model.entity.Post;
-import java.util.Date;
-import java.util.List;
-
-/**
- * 帖子数据库操作
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-public interface PostMapper extends BaseMapper {
-
- /**
- * 查询帖子列表(包括已被删除的数据)
- */
- List listPostWithDelete(Date minUpdateTime);
-
-}
-
-
-
-
diff --git a/src/main/java/top/peng/answerbi/mapper/PostThumbMapper.java b/src/main/java/top/peng/answerbi/mapper/PostThumbMapper.java
deleted file mode 100644
index 3b6eff6..0000000
--- a/src/main/java/top/peng/answerbi/mapper/PostThumbMapper.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package top.peng.answerbi.mapper;
-
-import top.peng.answerbi.model.entity.PostThumb;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-
-/**
- * 帖子点赞数据库操作
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-public interface PostThumbMapper extends BaseMapper {
-
-}
-
-
-
-
diff --git a/src/main/java/top/peng/answerbi/model/dto/post/PostAddRequest.java b/src/main/java/top/peng/answerbi/model/dto/post/PostAddRequest.java
deleted file mode 100644
index 353c4e3..0000000
--- a/src/main/java/top/peng/answerbi/model/dto/post/PostAddRequest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package top.peng.answerbi.model.dto.post;
-
-import java.io.Serializable;
-import java.util.List;
-import lombok.Data;
-
-/**
- * 创建请求
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@Data
-public class PostAddRequest implements Serializable {
-
- /**
- * 标题
- */
- private String title;
-
- /**
- * 内容
- */
- private String content;
-
- /**
- * 标签列表
- */
- private List tags;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/top/peng/answerbi/model/dto/post/PostEditRequest.java b/src/main/java/top/peng/answerbi/model/dto/post/PostEditRequest.java
deleted file mode 100644
index 271aef0..0000000
--- a/src/main/java/top/peng/answerbi/model/dto/post/PostEditRequest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package top.peng.answerbi.model.dto.post;
-
-import java.io.Serializable;
-import java.util.List;
-import lombok.Data;
-
-/**
- * 编辑请求
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@Data
-public class PostEditRequest implements Serializable {
-
- /**
- * id
- */
- private Long id;
-
- /**
- * 标题
- */
- private String title;
-
- /**
- * 内容
- */
- private String content;
-
- /**
- * 标签列表
- */
- private List tags;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/top/peng/answerbi/model/dto/post/PostEsDTO.java b/src/main/java/top/peng/answerbi/model/dto/post/PostEsDTO.java
deleted file mode 100644
index cad036d..0000000
--- a/src/main/java/top/peng/answerbi/model/dto/post/PostEsDTO.java
+++ /dev/null
@@ -1,125 +0,0 @@
-package top.peng.answerbi.model.dto.post;
-
-import com.google.common.reflect.TypeToken;
-import com.google.gson.Gson;
-import top.peng.answerbi.model.entity.Post;
-import java.io.Serializable;
-import java.util.Date;
-import java.util.List;
-import lombok.Data;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.BeanUtils;
-import org.springframework.data.annotation.Id;
-import org.springframework.data.elasticsearch.annotations.Field;
-import org.springframework.data.elasticsearch.annotations.FieldType;
-
-/**
- * 帖子 ES 包装类
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- **/
-// todo 取消注释开启 ES(须先配置 ES)
-//@Document(indexName = "post")
-@Data
-public class PostEsDTO implements Serializable {
-
- private static final String DATE_TIME_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
-
- /**
- * id
- */
- @Id
- private Long id;
-
- /**
- * 标题
- */
- private String title;
-
- /**
- * 内容
- */
- private String content;
-
- /**
- * 标签列表
- */
- private List tags;
-
- /**
- * 点赞数
- */
- private Integer thumbNum;
-
- /**
- * 收藏数
- */
- private Integer favourNum;
-
- /**
- * 创建用户 id
- */
- private Long userId;
-
- /**
- * 创建时间
- */
- @Field(index = false, store = true, type = FieldType.Date, format = {}, pattern = DATE_TIME_PATTERN)
- private Date createTime;
-
- /**
- * 更新时间
- */
- @Field(index = false, store = true, type = FieldType.Date, format = {}, pattern = DATE_TIME_PATTERN)
- private Date updateTime;
-
- /**
- * 是否删除
- */
- private Integer isDelete;
-
- private static final long serialVersionUID = 1L;
-
- private static final Gson GSON = new Gson();
-
- /**
- * 对象转包装类
- *
- * @param post
- * @return
- */
- public static PostEsDTO objToDto(Post post) {
- if (post == null) {
- return null;
- }
- PostEsDTO postEsDTO = new PostEsDTO();
- BeanUtils.copyProperties(post, postEsDTO);
- String tagsStr = post.getTags();
- if (StringUtils.isNotBlank(tagsStr)) {
- postEsDTO.setTags(GSON.fromJson(tagsStr, new TypeToken>() {
- }.getType()));
- }
- return postEsDTO;
- }
-
- /**
- * 包装类转对象
- *
- * @param postEsDTO
- * @return
- */
- public static Post dtoToObj(PostEsDTO postEsDTO) {
- if (postEsDTO == null) {
- return null;
- }
- Post post = new Post();
- BeanUtils.copyProperties(postEsDTO, post);
- List tagList = postEsDTO.getTags();
- if (CollectionUtils.isNotEmpty(tagList)) {
- post.setTags(GSON.toJson(tagList));
- }
- return post;
- }
-}
diff --git a/src/main/java/top/peng/answerbi/model/dto/post/PostQueryRequest.java b/src/main/java/top/peng/answerbi/model/dto/post/PostQueryRequest.java
deleted file mode 100644
index 54d6921..0000000
--- a/src/main/java/top/peng/answerbi/model/dto/post/PostQueryRequest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package top.peng.answerbi.model.dto.post;
-
-import top.peng.answerbi.common.PageRequest;
-import java.io.Serializable;
-import java.util.List;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * 查询请求
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@EqualsAndHashCode(callSuper = true)
-@Data
-public class PostQueryRequest extends PageRequest implements Serializable {
-
- /**
- * id
- */
- private Long id;
-
- /**
- * id
- */
- private Long notId;
-
- /**
- * 搜索词
- */
- private String searchText;
-
- /**
- * 标题
- */
- private String title;
-
- /**
- * 内容
- */
- private String content;
-
- /**
- * 标签列表
- */
- private List tags;
-
- /**
- * 至少有一个标签
- */
- private List orTags;
-
- /**
- * 创建用户 id
- */
- private Long userId;
-
- /**
- * 收藏用户 id
- */
- private Long favourUserId;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/top/peng/answerbi/model/dto/post/PostUpdateRequest.java b/src/main/java/top/peng/answerbi/model/dto/post/PostUpdateRequest.java
deleted file mode 100644
index 9ae482e..0000000
--- a/src/main/java/top/peng/answerbi/model/dto/post/PostUpdateRequest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package top.peng.answerbi.model.dto.post;
-
-import java.io.Serializable;
-import java.util.List;
-import lombok.Data;
-
-/**
- * 更新请求
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@Data
-public class PostUpdateRequest implements Serializable {
-
- /**
- * id
- */
- private Long id;
-
- /**
- * 标题
- */
- private String title;
-
- /**
- * 内容
- */
- private String content;
-
- /**
- * 标签列表
- */
- private List tags;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/top/peng/answerbi/model/dto/postfavour/PostFavourAddRequest.java b/src/main/java/top/peng/answerbi/model/dto/postfavour/PostFavourAddRequest.java
deleted file mode 100644
index 2ad0eff..0000000
--- a/src/main/java/top/peng/answerbi/model/dto/postfavour/PostFavourAddRequest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package top.peng.answerbi.model.dto.postfavour;
-
-import java.io.Serializable;
-import lombok.Data;
-
-/**
- * 帖子收藏 / 取消收藏请求
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@Data
-public class PostFavourAddRequest implements Serializable {
-
- /**
- * 帖子 id
- */
- private Long postId;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/top/peng/answerbi/model/dto/postfavour/PostFavourQueryRequest.java b/src/main/java/top/peng/answerbi/model/dto/postfavour/PostFavourQueryRequest.java
deleted file mode 100644
index 74494ac..0000000
--- a/src/main/java/top/peng/answerbi/model/dto/postfavour/PostFavourQueryRequest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package top.peng.answerbi.model.dto.postfavour;
-
-import top.peng.answerbi.common.PageRequest;
-import top.peng.answerbi.model.dto.post.PostQueryRequest;
-import java.io.Serializable;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * 帖子收藏查询请求
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-public class PostFavourQueryRequest extends PageRequest implements Serializable {
-
- /**
- * 帖子查询请求
- */
- private PostQueryRequest postQueryRequest;
-
- /**
- * 用户 id
- */
- private Long userId;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/top/peng/answerbi/model/dto/postthumb/PostThumbAddRequest.java b/src/main/java/top/peng/answerbi/model/dto/postthumb/PostThumbAddRequest.java
deleted file mode 100644
index 060b3f5..0000000
--- a/src/main/java/top/peng/answerbi/model/dto/postthumb/PostThumbAddRequest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package top.peng.answerbi.model.dto.postthumb;
-
-import java.io.Serializable;
-import lombok.Data;
-
-/**
- * 帖子点赞请求
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@Data
-public class PostThumbAddRequest implements Serializable {
-
- /**
- * 帖子 id
- */
- private Long postId;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/top/peng/answerbi/model/entity/Post.java b/src/main/java/top/peng/answerbi/model/entity/Post.java
deleted file mode 100644
index 67f65a6..0000000
--- a/src/main/java/top/peng/answerbi/model/entity/Post.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package top.peng.answerbi.model.entity;
-
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import com.baomidou.mybatisplus.annotation.TableName;
-import java.io.Serializable;
-import java.util.Date;
-import lombok.Data;
-
-/**
- * 帖子
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@TableName(value = "post")
-@Data
-public class Post implements Serializable {
-
- /**
- * id
- */
- @TableId(type = IdType.ASSIGN_ID)
- private Long id;
-
- /**
- * 标题
- */
- private String title;
-
- /**
- * 内容
- */
- private String content;
-
- /**
- * 标签列表 json
- */
- private String tags;
-
- /**
- * 点赞数
- */
- private Integer thumbNum;
-
- /**
- * 收藏数
- */
- private Integer favourNum;
-
- /**
- * 创建用户 id
- */
- private Long userId;
-
- /**
- * 创建时间
- */
- private Date createTime;
-
- /**
- * 更新时间
- */
- private Date updateTime;
-
- /**
- * 是否删除
- */
- @TableLogic
- private Integer isDelete;
-
- @TableField(exist = false)
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/top/peng/answerbi/model/entity/PostFavour.java b/src/main/java/top/peng/answerbi/model/entity/PostFavour.java
deleted file mode 100644
index 378b3dd..0000000
--- a/src/main/java/top/peng/answerbi/model/entity/PostFavour.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package top.peng.answerbi.model.entity;
-
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import java.io.Serializable;
-import java.util.Date;
-import lombok.Data;
-
-/**
- * 帖子收藏
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- **/
-@TableName(value = "post_favour")
-@Data
-public class PostFavour implements Serializable {
-
- /**
- * id
- */
- @TableId(type = IdType.AUTO)
- private Long id;
-
- /**
- * 帖子 id
- */
- private Long postId;
-
- /**
- * 创建用户 id
- */
- private Long userId;
-
- /**
- * 创建时间
- */
- private Date createTime;
-
- /**
- * 更新时间
- */
- private Date updateTime;
-
- @TableField(exist = false)
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/top/peng/answerbi/model/entity/PostThumb.java b/src/main/java/top/peng/answerbi/model/entity/PostThumb.java
deleted file mode 100644
index ef4ad1d..0000000
--- a/src/main/java/top/peng/answerbi/model/entity/PostThumb.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package top.peng.answerbi.model.entity;
-
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import java.io.Serializable;
-import java.util.Date;
-import lombok.Data;
-
-/**
- * 帖子点赞
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@TableName(value = "post_thumb")
-@Data
-public class PostThumb implements Serializable {
-
- /**
- * id
- */
- @TableId(type = IdType.AUTO)
- private Long id;
-
- /**
- * 帖子 id
- */
- private Long postId;
-
- /**
- * 创建用户 id
- */
- private Long userId;
-
- /**
- * 创建时间
- */
- private Date createTime;
-
- /**
- * 更新时间
- */
- private Date updateTime;
-
- @TableField(exist = false)
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/top/peng/answerbi/model/vo/PostVO.java b/src/main/java/top/peng/answerbi/model/vo/PostVO.java
deleted file mode 100644
index 59fa67f..0000000
--- a/src/main/java/top/peng/answerbi/model/vo/PostVO.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package top.peng.answerbi.model.vo;
-
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
-import top.peng.answerbi.model.entity.Post;
-import java.io.Serializable;
-import java.util.Date;
-import java.util.List;
-import lombok.Data;
-import org.springframework.beans.BeanUtils;
-
-/**
- * 帖子视图
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@Data
-public class PostVO implements Serializable {
-
- private final static Gson GSON = new Gson();
-
- /**
- * id
- */
- private Long id;
-
- /**
- * 标题
- */
- private String title;
-
- /**
- * 内容
- */
- private String content;
-
- /**
- * 点赞数
- */
- private Integer thumbNum;
-
- /**
- * 收藏数
- */
- private Integer favourNum;
-
- /**
- * 创建用户 id
- */
- private Long userId;
-
- /**
- * 创建时间
- */
- private Date createTime;
-
- /**
- * 更新时间
- */
- private Date updateTime;
-
- /**
- * 标签列表
- */
- private List tagList;
-
- /**
- * 创建人信息
- */
- private UserVO user;
-
- /**
- * 是否已点赞
- */
- private Boolean hasThumb;
-
- /**
- * 是否已收藏
- */
- private Boolean hasFavour;
-
- /**
- * 包装类转对象
- *
- * @param postVO
- * @return
- */
- public static Post voToObj(PostVO postVO) {
- if (postVO == null) {
- return null;
- }
- Post post = new Post();
- BeanUtils.copyProperties(postVO, post);
- List tagList = postVO.getTagList();
- if (tagList != null) {
- post.setTags(GSON.toJson(tagList));
- }
- return post;
- }
-
- /**
- * 对象转包装类
- *
- * @param post
- * @return
- */
- public static PostVO objToVo(Post post) {
- if (post == null) {
- return null;
- }
- PostVO postVO = new PostVO();
- BeanUtils.copyProperties(post, postVO);
- postVO.setTagList(GSON.fromJson(post.getTags(), new TypeToken>() {
- }.getType()));
- return postVO;
- }
-}
diff --git a/src/main/java/top/peng/answerbi/service/PostFavourService.java b/src/main/java/top/peng/answerbi/service/PostFavourService.java
deleted file mode 100644
index 5d48fc8..0000000
--- a/src/main/java/top/peng/answerbi/service/PostFavourService.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package top.peng.answerbi.service;
-
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.extension.service.IService;
-import top.peng.answerbi.model.entity.Post;
-import top.peng.answerbi.model.entity.PostFavour;
-import top.peng.answerbi.model.entity.User;
-
-/**
- * 帖子收藏服务
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-public interface PostFavourService extends IService {
-
- /**
- * 帖子收藏
- *
- * @param postId
- * @param loginUser
- * @return
- */
- int doPostFavour(long postId, User loginUser);
-
- /**
- * 分页获取用户收藏的帖子列表
- *
- * @param page
- * @param queryWrapper
- * @param favourUserId
- * @return
- */
- Page listFavourPostByPage(IPage page, Wrapper queryWrapper,
- long favourUserId);
-
- /**
- * 帖子收藏(内部服务)
- *
- * @param userId
- * @param postId
- * @return
- */
- int doPostFavourInner(long userId, long postId);
-}
diff --git a/src/main/java/top/peng/answerbi/service/PostService.java b/src/main/java/top/peng/answerbi/service/PostService.java
deleted file mode 100644
index 5b0c721..0000000
--- a/src/main/java/top/peng/answerbi/service/PostService.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package top.peng.answerbi.service;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.extension.service.IService;
-import top.peng.answerbi.model.dto.post.PostQueryRequest;
-import top.peng.answerbi.model.entity.Post;
-import top.peng.answerbi.model.vo.PostVO;
-import javax.servlet.http.HttpServletRequest;
-
-/**
- * 帖子服务
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-public interface PostService extends IService {
-
- /**
- * 校验
- *
- * @param post
- * @param add
- */
- void validPost(Post post, boolean add);
-
- /**
- * 获取查询条件
- *
- * @param postQueryRequest
- * @return
- */
- QueryWrapper getQueryWrapper(PostQueryRequest postQueryRequest);
-
- /**
- * 从 ES 查询
- *
- * @param postQueryRequest
- * @return
- */
- Page searchFromEs(PostQueryRequest postQueryRequest);
-
- /**
- * 获取帖子封装
- *
- * @param post
- * @param request
- * @return
- */
- PostVO getPostVO(Post post, HttpServletRequest request);
-
- /**
- * 分页获取帖子封装
- *
- * @param postPage
- * @param request
- * @return
- */
- Page getPostVOPage(Page postPage, HttpServletRequest request);
-}
diff --git a/src/main/java/top/peng/answerbi/service/PostThumbService.java b/src/main/java/top/peng/answerbi/service/PostThumbService.java
deleted file mode 100644
index a042f42..0000000
--- a/src/main/java/top/peng/answerbi/service/PostThumbService.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package top.peng.answerbi.service;
-
-import top.peng.answerbi.model.entity.PostThumb;
-import com.baomidou.mybatisplus.extension.service.IService;
-import top.peng.answerbi.model.entity.User;
-
-/**
- * 帖子点赞服务
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-public interface PostThumbService extends IService {
-
- /**
- * 点赞
- *
- * @param postId
- * @param loginUser
- * @return
- */
- int doPostThumb(long postId, User loginUser);
-
- /**
- * 帖子点赞(内部服务)
- *
- * @param userId
- * @param postId
- * @return
- */
- int doPostThumbInner(long userId, long postId);
-}
diff --git a/src/main/java/top/peng/answerbi/service/impl/PostFavourServiceImpl.java b/src/main/java/top/peng/answerbi/service/impl/PostFavourServiceImpl.java
deleted file mode 100644
index 6a7b92a..0000000
--- a/src/main/java/top/peng/answerbi/service/impl/PostFavourServiceImpl.java
+++ /dev/null
@@ -1,116 +0,0 @@
-package top.peng.answerbi.service.impl;
-
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import top.peng.answerbi.common.ErrorCode;
-import top.peng.answerbi.exception.BusinessException;
-import top.peng.answerbi.mapper.PostFavourMapper;
-import top.peng.answerbi.model.entity.Post;
-import top.peng.answerbi.model.entity.PostFavour;
-import top.peng.answerbi.model.entity.User;
-import top.peng.answerbi.service.PostFavourService;
-import top.peng.answerbi.service.PostService;
-import javax.annotation.Resource;
-import org.springframework.aop.framework.AopContext;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-/**
- * 帖子收藏服务实现
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@Service
-public class PostFavourServiceImpl extends ServiceImpl
- implements PostFavourService {
-
- @Resource
- private PostService postService;
-
- /**
- * 帖子收藏
- *
- * @param postId
- * @param loginUser
- * @return
- */
- @Override
- public int doPostFavour(long postId, User loginUser) {
- // 判断是否存在
- Post post = postService.getById(postId);
- if (post == null) {
- throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
- }
- // 是否已帖子收藏
- long userId = loginUser.getId();
- // 每个用户串行帖子收藏
- // 锁必须要包裹住事务方法
- PostFavourService postFavourService = (PostFavourService) AopContext.currentProxy();
- synchronized (String.valueOf(userId).intern()) {
- return postFavourService.doPostFavourInner(userId, postId);
- }
- }
-
- @Override
- public Page listFavourPostByPage(IPage page, Wrapper queryWrapper, long favourUserId) {
- if (favourUserId <= 0) {
- return new Page<>();
- }
- return baseMapper.listFavourPostByPage(page, queryWrapper, favourUserId);
- }
-
- /**
- * 封装了事务的方法
- *
- * @param userId
- * @param postId
- * @return
- */
- @Override
- @Transactional(rollbackFor = Exception.class)
- public int doPostFavourInner(long userId, long postId) {
- PostFavour postFavour = new PostFavour();
- postFavour.setUserId(userId);
- postFavour.setPostId(postId);
- QueryWrapper postFavourQueryWrapper = new QueryWrapper<>(postFavour);
- PostFavour oldPostFavour = this.getOne(postFavourQueryWrapper);
- boolean result;
- // 已收藏
- if (oldPostFavour != null) {
- result = this.remove(postFavourQueryWrapper);
- if (result) {
- // 帖子收藏数 - 1
- result = postService.update()
- .eq("id", postId)
- .gt("favourNum", 0)
- .setSql("favourNum = favourNum - 1")
- .update();
- return result ? -1 : 0;
- } else {
- throw new BusinessException(ErrorCode.SYSTEM_ERROR);
- }
- } else {
- // 未帖子收藏
- result = this.save(postFavour);
- if (result) {
- // 帖子收藏数 + 1
- result = postService.update()
- .eq("id", postId)
- .setSql("favourNum = favourNum + 1")
- .update();
- return result ? 1 : 0;
- } else {
- throw new BusinessException(ErrorCode.SYSTEM_ERROR);
- }
- }
- }
-
-}
-
-
-
-
diff --git a/src/main/java/top/peng/answerbi/service/impl/PostServiceImpl.java b/src/main/java/top/peng/answerbi/service/impl/PostServiceImpl.java
deleted file mode 100644
index 2ecf81e..0000000
--- a/src/main/java/top/peng/answerbi/service/impl/PostServiceImpl.java
+++ /dev/null
@@ -1,316 +0,0 @@
-package top.peng.answerbi.service.impl;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.google.gson.Gson;
-import top.peng.answerbi.common.ErrorCode;
-import top.peng.answerbi.constant.CommonConstant;
-import top.peng.answerbi.exception.BusinessException;
-import top.peng.answerbi.exception.ThrowUtils;
-import top.peng.answerbi.mapper.PostFavourMapper;
-import top.peng.answerbi.mapper.PostMapper;
-import top.peng.answerbi.mapper.PostThumbMapper;
-import top.peng.answerbi.model.dto.post.PostEsDTO;
-import top.peng.answerbi.model.dto.post.PostQueryRequest;
-import top.peng.answerbi.model.entity.Post;
-import top.peng.answerbi.model.entity.PostFavour;
-import top.peng.answerbi.model.entity.PostThumb;
-import top.peng.answerbi.model.entity.User;
-import top.peng.answerbi.model.vo.PostVO;
-import top.peng.answerbi.model.vo.UserVO;
-import top.peng.answerbi.service.PostService;
-import top.peng.answerbi.service.UserService;
-import top.peng.answerbi.utils.SqlUtils;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.ObjectUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.elasticsearch.index.query.BoolQueryBuilder;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.elasticsearch.search.sort.SortBuilder;
-import org.elasticsearch.search.sort.SortBuilders;
-import org.elasticsearch.search.sort.SortOrder;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
-import org.springframework.data.elasticsearch.core.SearchHit;
-import org.springframework.data.elasticsearch.core.SearchHits;
-import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
-import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
-import org.springframework.stereotype.Service;
-
-/**
- * 帖子服务实现
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@Service
-@Slf4j
-public class PostServiceImpl extends ServiceImpl implements PostService {
-
- private final static Gson GSON = new Gson();
-
- @Resource
- private UserService userService;
-
- @Resource
- private PostThumbMapper postThumbMapper;
-
- @Resource
- private PostFavourMapper postFavourMapper;
-
- @Resource
- private ElasticsearchRestTemplate elasticsearchRestTemplate;
-
- @Override
- public void validPost(Post post, boolean add) {
- if (post == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- String title = post.getTitle();
- String content = post.getContent();
- String tags = post.getTags();
- // 创建时,参数不能为空
- if (add) {
- ThrowUtils.throwIf(StringUtils.isAnyBlank(title, content, tags), ErrorCode.PARAMS_ERROR);
- }
- // 有参数则校验
- if (StringUtils.isNotBlank(title) && title.length() > 80) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR, "标题过长");
- }
- if (StringUtils.isNotBlank(content) && content.length() > 8192) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR, "内容过长");
- }
- }
-
- /**
- * 获取查询包装类
- *
- * @param postQueryRequest
- * @return
- */
- @Override
- public QueryWrapper getQueryWrapper(PostQueryRequest postQueryRequest) {
- QueryWrapper queryWrapper = new QueryWrapper<>();
- if (postQueryRequest == null) {
- return queryWrapper;
- }
- String searchText = postQueryRequest.getSearchText();
- String sortField = postQueryRequest.getSortField();
- String sortOrder = postQueryRequest.getSortOrder();
- Long id = postQueryRequest.getId();
- String title = postQueryRequest.getTitle();
- String content = postQueryRequest.getContent();
- List tagList = postQueryRequest.getTags();
- Long userId = postQueryRequest.getUserId();
- Long notId = postQueryRequest.getNotId();
- // 拼接查询条件
- if (StringUtils.isNotBlank(searchText)) {
- queryWrapper.like("title", searchText).or().like("content", searchText);
- }
- queryWrapper.like(StringUtils.isNotBlank(title), "title", title);
- queryWrapper.like(StringUtils.isNotBlank(content), "content", content);
- if (CollectionUtils.isNotEmpty(tagList)) {
- for (String tag : tagList) {
- queryWrapper.like("tags", "\"" + tag + "\"");
- }
- }
- queryWrapper.ne(ObjectUtils.isNotEmpty(notId), "id", notId);
- queryWrapper.eq(ObjectUtils.isNotEmpty(id), "id", id);
- queryWrapper.eq(ObjectUtils.isNotEmpty(userId), "userId", userId);
- queryWrapper.eq("isDelete", false);
- queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
- sortField);
- return queryWrapper;
- }
-
- @Override
- public Page searchFromEs(PostQueryRequest postQueryRequest) {
- Long id = postQueryRequest.getId();
- Long notId = postQueryRequest.getNotId();
- String searchText = postQueryRequest.getSearchText();
- String title = postQueryRequest.getTitle();
- String content = postQueryRequest.getContent();
- List tagList = postQueryRequest.getTags();
- List orTagList = postQueryRequest.getOrTags();
- Long userId = postQueryRequest.getUserId();
- // es 起始页为 0
- long current = postQueryRequest.getCurrent() - 1;
- long pageSize = postQueryRequest.getPageSize();
- String sortField = postQueryRequest.getSortField();
- String sortOrder = postQueryRequest.getSortOrder();
- BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
- // 过滤
- boolQueryBuilder.filter(QueryBuilders.termQuery("isDelete", 0));
- if (id != null) {
- boolQueryBuilder.filter(QueryBuilders.termQuery("id", id));
- }
- if (notId != null) {
- boolQueryBuilder.mustNot(QueryBuilders.termQuery("id", notId));
- }
- if (userId != null) {
- boolQueryBuilder.filter(QueryBuilders.termQuery("userId", userId));
- }
- // 必须包含所有标签
- if (CollectionUtils.isNotEmpty(tagList)) {
- for (String tag : tagList) {
- boolQueryBuilder.filter(QueryBuilders.termQuery("tags", tag));
- }
- }
- // 包含任何一个标签即可
- if (CollectionUtils.isNotEmpty(orTagList)) {
- BoolQueryBuilder orTagBoolQueryBuilder = QueryBuilders.boolQuery();
- for (String tag : orTagList) {
- orTagBoolQueryBuilder.should(QueryBuilders.termQuery("tags", tag));
- }
- orTagBoolQueryBuilder.minimumShouldMatch(1);
- boolQueryBuilder.filter(orTagBoolQueryBuilder);
- }
- // 按关键词检索
- if (StringUtils.isNotBlank(searchText)) {
- boolQueryBuilder.should(QueryBuilders.matchQuery("title", searchText));
- boolQueryBuilder.should(QueryBuilders.matchQuery("description", searchText));
- boolQueryBuilder.should(QueryBuilders.matchQuery("content", searchText));
- boolQueryBuilder.minimumShouldMatch(1);
- }
- // 按标题检索
- if (StringUtils.isNotBlank(title)) {
- boolQueryBuilder.should(QueryBuilders.matchQuery("title", title));
- boolQueryBuilder.minimumShouldMatch(1);
- }
- // 按内容检索
- if (StringUtils.isNotBlank(content)) {
- boolQueryBuilder.should(QueryBuilders.matchQuery("content", content));
- boolQueryBuilder.minimumShouldMatch(1);
- }
- // 排序
- SortBuilder> sortBuilder = SortBuilders.scoreSort();
- if (StringUtils.isNotBlank(sortField)) {
- sortBuilder = SortBuilders.fieldSort(sortField);
- sortBuilder.order(CommonConstant.SORT_ORDER_ASC.equals(sortOrder) ? SortOrder.ASC : SortOrder.DESC);
- }
- // 分页
- PageRequest pageRequest = PageRequest.of((int) current, (int) pageSize);
- // 构造查询
- NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(boolQueryBuilder)
- .withPageable(pageRequest).withSorts(sortBuilder).build();
- SearchHits searchHits = elasticsearchRestTemplate.search(searchQuery, PostEsDTO.class);
- Page page = new Page<>();
- page.setTotal(searchHits.getTotalHits());
- List resourceList = new ArrayList<>();
- // 查出结果后,从 db 获取最新动态数据(比如点赞数)
- if (searchHits.hasSearchHits()) {
- List> searchHitList = searchHits.getSearchHits();
- List postIdList = searchHitList.stream().map(searchHit -> searchHit.getContent().getId())
- .collect(Collectors.toList());
- List postList = baseMapper.selectBatchIds(postIdList);
- if (postList != null) {
- Map> idPostMap = postList.stream().collect(Collectors.groupingBy(Post::getId));
- postIdList.forEach(postId -> {
- if (idPostMap.containsKey(postId)) {
- resourceList.add(idPostMap.get(postId).get(0));
- } else {
- // 从 es 清空 db 已物理删除的数据
- String delete = elasticsearchRestTemplate.delete(String.valueOf(postId), PostEsDTO.class);
- log.info("delete post {}", delete);
- }
- });
- }
- }
- page.setRecords(resourceList);
- return page;
- }
-
- @Override
- public PostVO getPostVO(Post post, HttpServletRequest request) {
- PostVO postVO = PostVO.objToVo(post);
- long postId = post.getId();
- // 1. 关联查询用户信息
- Long userId = post.getUserId();
- User user = null;
- if (userId != null && userId > 0) {
- user = userService.getById(userId);
- }
- UserVO userVO = userService.getUserVO(user);
- postVO.setUser(userVO);
- // 2. 已登录,获取用户点赞、收藏状态
- User loginUser = userService.getLoginUserPermitNull(request);
- if (loginUser != null) {
- // 获取点赞
- QueryWrapper postThumbQueryWrapper = new QueryWrapper<>();
- postThumbQueryWrapper.in("postId", postId);
- postThumbQueryWrapper.eq("userId", loginUser.getId());
- PostThumb postThumb = postThumbMapper.selectOne(postThumbQueryWrapper);
- postVO.setHasThumb(postThumb != null);
- // 获取收藏
- QueryWrapper postFavourQueryWrapper = new QueryWrapper<>();
- postFavourQueryWrapper.in("postId", postId);
- postFavourQueryWrapper.eq("userId", loginUser.getId());
- PostFavour postFavour = postFavourMapper.selectOne(postFavourQueryWrapper);
- postVO.setHasFavour(postFavour != null);
- }
- return postVO;
- }
-
- @Override
- public Page getPostVOPage(Page postPage, HttpServletRequest request) {
- List postList = postPage.getRecords();
- Page postVOPage = new Page<>(postPage.getCurrent(), postPage.getSize(), postPage.getTotal());
- if (CollectionUtils.isEmpty(postList)) {
- return postVOPage;
- }
- // 1. 关联查询用户信息
- Set userIdSet = postList.stream().map(Post::getUserId).collect(Collectors.toSet());
- Map> userIdUserListMap = userService.listByIds(userIdSet).stream()
- .collect(Collectors.groupingBy(User::getId));
- // 2. 已登录,获取用户点赞、收藏状态
- Map postIdHasThumbMap = new HashMap<>();
- Map postIdHasFavourMap = new HashMap<>();
- User loginUser = userService.getLoginUserPermitNull(request);
- if (loginUser != null) {
- Set postIdSet = postList.stream().map(Post::getId).collect(Collectors.toSet());
- loginUser = userService.getLoginUser(request);
- // 获取点赞
- QueryWrapper postThumbQueryWrapper = new QueryWrapper<>();
- postThumbQueryWrapper.in("postId", postIdSet);
- postThumbQueryWrapper.eq("userId", loginUser.getId());
- List postPostThumbList = postThumbMapper.selectList(postThumbQueryWrapper);
- postPostThumbList.forEach(postPostThumb -> postIdHasThumbMap.put(postPostThumb.getPostId(), true));
- // 获取收藏
- QueryWrapper postFavourQueryWrapper = new QueryWrapper<>();
- postFavourQueryWrapper.in("postId", postIdSet);
- postFavourQueryWrapper.eq("userId", loginUser.getId());
- List postFavourList = postFavourMapper.selectList(postFavourQueryWrapper);
- postFavourList.forEach(postFavour -> postIdHasFavourMap.put(postFavour.getPostId(), true));
- }
- // 填充信息
- List postVOList = postList.stream().map(post -> {
- PostVO postVO = PostVO.objToVo(post);
- Long userId = post.getUserId();
- User user = null;
- if (userIdUserListMap.containsKey(userId)) {
- user = userIdUserListMap.get(userId).get(0);
- }
- postVO.setUser(userService.getUserVO(user));
- postVO.setHasThumb(postIdHasThumbMap.getOrDefault(post.getId(), false));
- postVO.setHasFavour(postIdHasFavourMap.getOrDefault(post.getId(), false));
- return postVO;
- }).collect(Collectors.toList());
- postVOPage.setRecords(postVOList);
- return postVOPage;
- }
-
-}
-
-
-
-
diff --git a/src/main/java/top/peng/answerbi/service/impl/PostThumbServiceImpl.java b/src/main/java/top/peng/answerbi/service/impl/PostThumbServiceImpl.java
deleted file mode 100644
index 36351b5..0000000
--- a/src/main/java/top/peng/answerbi/service/impl/PostThumbServiceImpl.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package top.peng.answerbi.service.impl;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import top.peng.answerbi.common.ErrorCode;
-import top.peng.answerbi.exception.BusinessException;
-import top.peng.answerbi.mapper.PostThumbMapper;
-import top.peng.answerbi.model.entity.Post;
-import top.peng.answerbi.model.entity.PostThumb;
-import top.peng.answerbi.model.entity.User;
-import top.peng.answerbi.service.PostService;
-import top.peng.answerbi.service.PostThumbService;
-import javax.annotation.Resource;
-import org.springframework.aop.framework.AopContext;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-/**
- * 帖子点赞服务实现
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@Service
-public class PostThumbServiceImpl extends ServiceImpl
- implements PostThumbService {
-
- @Resource
- private PostService postService;
-
- /**
- * 点赞
- *
- * @param postId
- * @param loginUser
- * @return
- */
- @Override
- public int doPostThumb(long postId, User loginUser) {
- // 判断实体是否存在,根据类别获取实体
- Post post = postService.getById(postId);
- if (post == null) {
- throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
- }
- // 是否已点赞
- long userId = loginUser.getId();
- // 每个用户串行点赞
- // 锁必须要包裹住事务方法
- PostThumbService postThumbService = (PostThumbService) AopContext.currentProxy();
- synchronized (String.valueOf(userId).intern()) {
- return postThumbService.doPostThumbInner(userId, postId);
- }
- }
-
- /**
- * 封装了事务的方法
- *
- * @param userId
- * @param postId
- * @return
- */
- @Override
- @Transactional(rollbackFor = Exception.class)
- public int doPostThumbInner(long userId, long postId) {
- PostThumb postThumb = new PostThumb();
- postThumb.setUserId(userId);
- postThumb.setPostId(postId);
- QueryWrapper thumbQueryWrapper = new QueryWrapper<>(postThumb);
- PostThumb oldPostThumb = this.getOne(thumbQueryWrapper);
- boolean result;
- // 已点赞
- if (oldPostThumb != null) {
- result = this.remove(thumbQueryWrapper);
- if (result) {
- // 点赞数 - 1
- result = postService.update()
- .eq("id", postId)
- .gt("thumbNum", 0)
- .setSql("thumbNum = thumbNum - 1")
- .update();
- return result ? -1 : 0;
- } else {
- throw new BusinessException(ErrorCode.SYSTEM_ERROR);
- }
- } else {
- // 未点赞
- result = this.save(postThumb);
- if (result) {
- // 点赞数 + 1
- result = postService.update()
- .eq("id", postId)
- .setSql("thumbNum = thumbNum + 1")
- .update();
- return result ? 1 : 0;
- } else {
- throw new BusinessException(ErrorCode.SYSTEM_ERROR);
- }
- }
- }
-
-}
-
-
-
-
diff --git a/src/main/resources/mapper/PostFavourMapper.xml b/src/main/resources/mapper/PostFavourMapper.xml
deleted file mode 100644
index ba4f5c5..0000000
--- a/src/main/resources/mapper/PostFavourMapper.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
- id,postId,userId,
- createTime,updateTime
-
-
-
-
diff --git a/src/main/resources/mapper/PostMapper.xml b/src/main/resources/mapper/PostMapper.xml
deleted file mode 100644
index b871ffb..0000000
--- a/src/main/resources/mapper/PostMapper.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- id,title,content,tags,
- thumbNum,favourNum,userId,
- createTime,updateTime,isDelete
-
-
-
-
diff --git a/src/main/resources/mapper/PostThumbMapper.xml b/src/main/resources/mapper/PostThumbMapper.xml
deleted file mode 100644
index fd5604c..0000000
--- a/src/main/resources/mapper/PostThumbMapper.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
- id,postId,
- userId,createTime,updateTime
-
-
diff --git a/src/main/resources/test_excel.xlsx b/src/main/resources/test_excel.xlsx
deleted file mode 100644
index 9e4c4c6..0000000
Binary files a/src/main/resources/test_excel.xlsx and /dev/null differ
diff --git a/src/test/java/top/peng/answerbi/esdao/PostEsDaoTest.java b/src/test/java/top/peng/answerbi/esdao/PostEsDaoTest.java
deleted file mode 100644
index 8457345..0000000
--- a/src/test/java/top/peng/answerbi/esdao/PostEsDaoTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package top.peng.answerbi.esdao;
-
-import top.peng.answerbi.model.dto.post.PostEsDTO;
-import top.peng.answerbi.model.dto.post.PostQueryRequest;
-import top.peng.answerbi.model.entity.Post;
-import top.peng.answerbi.service.PostService;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Optional;
-import javax.annotation.Resource;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Sort;
-
-/**
- * 帖子 ES 操作测试
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@SpringBootTest
-public class PostEsDaoTest {
-
- @Resource
- private PostEsDao postEsDao;
-
- @Resource
- private PostService postService;
-
- @Test
- void test() {
- PostQueryRequest postQueryRequest = new PostQueryRequest();
- com.baomidou.mybatisplus.extension.plugins.pagination.Page page =
- postService.searchFromEs(postQueryRequest);
- System.out.println(page);
- }
-
- @Test
- void testSelect() {
- System.out.println(postEsDao.count());
- Page PostPage = postEsDao.findAll(
- PageRequest.of(0, 5, Sort.by("createTime")));
- List postList = PostPage.getContent();
- System.out.println(postList);
- }
-
- @Test
- void testAdd() {
- PostEsDTO postEsDTO = new PostEsDTO();
- postEsDTO.setId(1L);
- postEsDTO.setTitle("test");
- postEsDTO.setContent("test");
- postEsDTO.setTags(Arrays.asList("java", "python"));
- postEsDTO.setThumbNum(1);
- postEsDTO.setFavourNum(1);
- postEsDTO.setUserId(1L);
- postEsDTO.setCreateTime(new Date());
- postEsDTO.setUpdateTime(new Date());
- postEsDTO.setIsDelete(0);
- postEsDao.save(postEsDTO);
- System.out.println(postEsDTO.getId());
- }
-
- @Test
- void testFindById() {
- Optional postEsDTO = postEsDao.findById(1L);
- System.out.println(postEsDTO);
- }
-
- @Test
- void testCount() {
- System.out.println(postEsDao.count());
- }
-
- @Test
- void testFindByCategory() {
- List postEsDaoTestList = postEsDao.findByUserId(1L);
- System.out.println(postEsDaoTestList);
- }
-}
diff --git a/src/test/java/top/peng/answerbi/mapper/PostFavourMapperTest.java b/src/test/java/top/peng/answerbi/mapper/PostFavourMapperTest.java
deleted file mode 100644
index efd51db..0000000
--- a/src/test/java/top/peng/answerbi/mapper/PostFavourMapperTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package top.peng.answerbi.mapper;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import top.peng.answerbi.model.entity.Post;
-import javax.annotation.Resource;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-/**
- * 帖子收藏数据库操作测试
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@SpringBootTest
-class PostFavourMapperTest {
-
- @Resource
- private PostFavourMapper postFavourMapper;
-
- @Test
- void listUserFavourPostByPage() {
- IPage page = new Page<>(2, 1);
- QueryWrapper queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("id", 1);
- queryWrapper.like("content", "a");
- IPage result = postFavourMapper.listFavourPostByPage(page, queryWrapper, 1);
- Assertions.assertNotNull(result);
- }
-}
\ No newline at end of file
diff --git a/src/test/java/top/peng/answerbi/mapper/PostMapperTest.java b/src/test/java/top/peng/answerbi/mapper/PostMapperTest.java
deleted file mode 100644
index adf59ab..0000000
--- a/src/test/java/top/peng/answerbi/mapper/PostMapperTest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package top.peng.answerbi.mapper;
-
-import top.peng.answerbi.model.entity.Post;
-import java.util.Date;
-import java.util.List;
-import javax.annotation.Resource;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-/**
- * 帖子数据库操作测试
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@SpringBootTest
-class PostMapperTest {
-
- @Resource
- private PostMapper postMapper;
-
- @Test
- void listPostWithDelete() {
- List postList = postMapper.listPostWithDelete(new Date());
- Assertions.assertNotNull(postList);
- }
-}
\ No newline at end of file
diff --git a/src/test/java/top/peng/answerbi/service/PostFavourServiceTest.java b/src/test/java/top/peng/answerbi/service/PostFavourServiceTest.java
deleted file mode 100644
index b9a7277..0000000
--- a/src/test/java/top/peng/answerbi/service/PostFavourServiceTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package top.peng.answerbi.service;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import top.peng.answerbi.model.entity.Post;
-import javax.annotation.Resource;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-import top.peng.answerbi.model.entity.User;
-
-/**
- * 帖子收藏服务测试
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@SpringBootTest
-class PostFavourServiceTest {
-
- @Resource
- private PostFavourService postFavourService;
-
- private static final User loginUser = new User();
-
- @BeforeAll
- static void setUp() {
- loginUser.setId(1L);
- }
-
- @Test
- void doPostFavour() {
- int i = postFavourService.doPostFavour(1L, loginUser);
- Assertions.assertTrue(i >= 0);
- }
-
- @Test
- void listFavourPostByPage() {
- QueryWrapper postQueryWrapper = new QueryWrapper<>();
- postQueryWrapper.eq("id", 1L);
- postFavourService.listFavourPostByPage(Page.of(0, 1), postQueryWrapper, loginUser.getId());
- }
-}
diff --git a/src/test/java/top/peng/answerbi/service/PostServiceTest.java b/src/test/java/top/peng/answerbi/service/PostServiceTest.java
deleted file mode 100644
index 5cdc354..0000000
--- a/src/test/java/top/peng/answerbi/service/PostServiceTest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package top.peng.answerbi.service;
-
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import top.peng.answerbi.model.dto.post.PostQueryRequest;
-import top.peng.answerbi.model.entity.Post;
-import javax.annotation.Resource;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-/**
- * 帖子服务测试
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@SpringBootTest
-class PostServiceTest {
-
- @Resource
- private PostService postService;
-
- @Test
- void searchFromEs() {
- PostQueryRequest postQueryRequest = new PostQueryRequest();
- postQueryRequest.setUserId(1L);
- Page postPage = postService.searchFromEs(postQueryRequest);
- Assertions.assertNotNull(postPage);
- }
-
-}
\ No newline at end of file
diff --git a/src/test/java/top/peng/answerbi/service/PostThumbServiceTest.java b/src/test/java/top/peng/answerbi/service/PostThumbServiceTest.java
deleted file mode 100644
index 823856b..0000000
--- a/src/test/java/top/peng/answerbi/service/PostThumbServiceTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package top.peng.answerbi.service;
-
-import javax.annotation.Resource;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-import top.peng.answerbi.model.entity.User;
-
-/**
- * 帖子点赞服务测试
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@SpringBootTest
-class PostThumbServiceTest {
-
- @Resource
- private PostThumbService postThumbService;
-
- private static final User loginUser = new User();
-
- @BeforeAll
- static void setUp() {
- loginUser.setId(1L);
- }
-
- @Test
- void doPostThumb() {
- int i = postThumbService.doPostThumb(1L, loginUser);
- Assertions.assertTrue(i >= 0);
- }
-}
diff --git a/src/test/java/top/peng/answerbi/utils/EasyExcelTest.java b/src/test/java/top/peng/answerbi/utils/EasyExcelTest.java
deleted file mode 100644
index 2efd5f7..0000000
--- a/src/test/java/top/peng/answerbi/utils/EasyExcelTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package top.peng.answerbi.utils;
-
-import com.alibaba.excel.EasyExcel;
-import com.alibaba.excel.support.ExcelTypeEnum;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.util.ResourceUtils;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.util.List;
-import java.util.Map;
-
-/**
- * EasyExcel 测试
- *
- * @author yunpeng
- * @version 1.0 2023/5/16
- */
-@SpringBootTest
-public class EasyExcelTest {
-
- @Test
- public void doImport() throws FileNotFoundException {
- File file = ResourceUtils.getFile("classpath:test_excel.xlsx");
- List