打包
This commit is contained in:
@@ -1,53 +0,0 @@
|
|||||||
package com.yupi.springbootinit.config;
|
|
||||||
|
|
||||||
import com.qcloud.cos.COSClient;
|
|
||||||
import com.qcloud.cos.ClientConfig;
|
|
||||||
import com.qcloud.cos.auth.BasicCOSCredentials;
|
|
||||||
import com.qcloud.cos.auth.COSCredentials;
|
|
||||||
import com.qcloud.cos.region.Region;
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 腾讯云对象存储客户端
|
|
||||||
*
|
|
||||||
* @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
|
||||||
* @from <a href="https://yupi.icu">编程导航知识星球</a>
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@ConfigurationProperties(prefix = "cos.client")
|
|
||||||
@Data
|
|
||||||
public class CosClientConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* accessKey
|
|
||||||
*/
|
|
||||||
private String accessKey;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* secretKey
|
|
||||||
*/
|
|
||||||
private String secretKey;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 区域
|
|
||||||
*/
|
|
||||||
private String region;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 桶名
|
|
||||||
*/
|
|
||||||
private String bucket;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public COSClient cosClient() {
|
|
||||||
// 初始化用户身份信息(secretId, secretKey)
|
|
||||||
COSCredentials cred = new BasicCOSCredentials(accessKey, secretKey);
|
|
||||||
// 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
|
|
||||||
ClientConfig clientConfig = new ClientConfig(new Region(region));
|
|
||||||
// 生成cos客户端
|
|
||||||
return new COSClient(cred, clientConfig);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,6 @@ import com.yupi.springbootinit.common.ErrorCode;
|
|||||||
import com.yupi.springbootinit.common.ResultUtils;
|
import com.yupi.springbootinit.common.ResultUtils;
|
||||||
import com.yupi.springbootinit.exception.BusinessException;
|
import com.yupi.springbootinit.exception.BusinessException;
|
||||||
import com.yupi.springbootinit.exception.ThrowUtils;
|
import com.yupi.springbootinit.exception.ThrowUtils;
|
||||||
import com.yupi.springbootinit.manager.CosManager;
|
|
||||||
import com.yupi.springbootinit.model.dto.dish.DishAddRequest;
|
import com.yupi.springbootinit.model.dto.dish.DishAddRequest;
|
||||||
import com.yupi.springbootinit.model.dto.dish.DishRandomRequest;
|
import com.yupi.springbootinit.model.dto.dish.DishRandomRequest;
|
||||||
import com.yupi.springbootinit.model.dto.dish.DishUpdataRequest;
|
import com.yupi.springbootinit.model.dto.dish.DishUpdataRequest;
|
||||||
@@ -32,9 +31,6 @@ public class DishController {
|
|||||||
@Resource
|
@Resource
|
||||||
private DishService dishService;
|
private DishService dishService;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private CosManager cosManager;
|
|
||||||
|
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
public BaseResponse<Long> add(@ModelAttribute DishAddRequest dishAddRequest, HttpServletRequest request) {
|
public BaseResponse<Long> add(@ModelAttribute DishAddRequest dishAddRequest, HttpServletRequest request) {
|
||||||
if (dishAddRequest == null) {
|
if (dishAddRequest == null) {
|
||||||
|
|||||||
@@ -1,108 +0,0 @@
|
|||||||
package com.yupi.springbootinit.controller;
|
|
||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
|
||||||
import com.yupi.springbootinit.common.BaseResponse;
|
|
||||||
import com.yupi.springbootinit.common.ErrorCode;
|
|
||||||
import com.yupi.springbootinit.common.ResultUtils;
|
|
||||||
import com.yupi.springbootinit.constant.FileConstant;
|
|
||||||
import com.yupi.springbootinit.exception.BusinessException;
|
|
||||||
import com.yupi.springbootinit.manager.CosManager;
|
|
||||||
import com.yupi.springbootinit.model.dto.file.UploadFileRequest;
|
|
||||||
import com.yupi.springbootinit.model.entity.User;
|
|
||||||
import com.yupi.springbootinit.model.enums.FileUploadBizEnum;
|
|
||||||
import com.yupi.springbootinit.service.UserService;
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestPart;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件接口
|
|
||||||
*
|
|
||||||
* @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
|
||||||
* @from <a href="https://yupi.icu">编程导航知识星球</a>
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/file")
|
|
||||||
@Slf4j
|
|
||||||
public class FileController {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private UserService userService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private CosManager cosManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件上传
|
|
||||||
*
|
|
||||||
* @param multipartFile
|
|
||||||
* @param uploadFileRequest
|
|
||||||
* @param request
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@PostMapping("/upload")
|
|
||||||
public BaseResponse<String> uploadFile(@RequestPart("file") MultipartFile multipartFile,
|
|
||||||
UploadFileRequest uploadFileRequest, HttpServletRequest request) {
|
|
||||||
String biz = uploadFileRequest.getBiz();
|
|
||||||
FileUploadBizEnum fileUploadBizEnum = FileUploadBizEnum.getEnumByValue(biz);
|
|
||||||
if (fileUploadBizEnum == null) {
|
|
||||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
|
||||||
}
|
|
||||||
validFile(multipartFile, fileUploadBizEnum);
|
|
||||||
User loginUser = userService.getLoginUser(request);
|
|
||||||
// 文件目录:根据业务、用户来划分
|
|
||||||
String uuid = RandomStringUtils.randomAlphanumeric(8);
|
|
||||||
String filename = uuid + "-" + multipartFile.getOriginalFilename();
|
|
||||||
String filepath = String.format("/%s/%s/%s", fileUploadBizEnum.getValue(), loginUser.getId(), filename);
|
|
||||||
File file = null;
|
|
||||||
try {
|
|
||||||
// 上传文件
|
|
||||||
file = File.createTempFile(filepath, null);
|
|
||||||
multipartFile.transferTo(file);
|
|
||||||
cosManager.putObject(filepath, file);
|
|
||||||
// 返回可访问地址
|
|
||||||
return ResultUtils.success(FileConstant.COS_HOST + filepath);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("file upload error, filepath = " + filepath, e);
|
|
||||||
throw new BusinessException(ErrorCode.SYSTEM_ERROR, "上传失败");
|
|
||||||
} finally {
|
|
||||||
if (file != null) {
|
|
||||||
// 删除临时文件
|
|
||||||
boolean delete = file.delete();
|
|
||||||
if (!delete) {
|
|
||||||
log.error("file delete error, filepath = {}", filepath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验文件
|
|
||||||
*
|
|
||||||
* @param multipartFile
|
|
||||||
* @param fileUploadBizEnum 业务类型
|
|
||||||
*/
|
|
||||||
private void validFile(MultipartFile multipartFile, FileUploadBizEnum fileUploadBizEnum) {
|
|
||||||
// 文件大小
|
|
||||||
long fileSize = multipartFile.getSize();
|
|
||||||
// 文件后缀
|
|
||||||
String fileSuffix = FileUtil.getSuffix(multipartFile.getOriginalFilename());
|
|
||||||
final long ONE_M = 1024 * 1024L;
|
|
||||||
if (FileUploadBizEnum.USER_AVATAR.equals(fileUploadBizEnum)) {
|
|
||||||
if (fileSize > ONE_M) {
|
|
||||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "文件大小不能超过 1M");
|
|
||||||
}
|
|
||||||
if (!Arrays.asList("jpeg", "jpg", "svg", "png", "webp").contains(fileSuffix)) {
|
|
||||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "文件类型错误");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package com.yupi.springbootinit.manager;
|
|
||||||
|
|
||||||
import com.qcloud.cos.COSClient;
|
|
||||||
import com.qcloud.cos.model.PutObjectRequest;
|
|
||||||
import com.qcloud.cos.model.PutObjectResult;
|
|
||||||
import com.yupi.springbootinit.config.CosClientConfig;
|
|
||||||
import java.io.File;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cos 对象存储操作
|
|
||||||
*
|
|
||||||
* @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
|
||||||
* @from <a href="https://yupi.icu">编程导航知识星球</a>
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class CosManager {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private CosClientConfig cosClientConfig;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private COSClient cosClient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 上传对象
|
|
||||||
*
|
|
||||||
* @param key 唯一键
|
|
||||||
* @param localFilePath 本地文件路径
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public PutObjectResult putObject(String key, String localFilePath) {
|
|
||||||
PutObjectRequest putObjectRequest = new PutObjectRequest(cosClientConfig.getBucket(), key,
|
|
||||||
new File(localFilePath));
|
|
||||||
return cosClient.putObject(putObjectRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 上传对象
|
|
||||||
*
|
|
||||||
* @param key 唯一键
|
|
||||||
* @param file 文件
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public PutObjectResult putObject(String key, File file) {
|
|
||||||
PutObjectRequest putObjectRequest = new PutObjectRequest(cosClientConfig.getBucket(), key,
|
|
||||||
file);
|
|
||||||
return cosClient.putObject(putObjectRequest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,11 +6,11 @@ server:
|
|||||||
spring:
|
spring:
|
||||||
# 数据库配置
|
# 数据库配置
|
||||||
# todo 需替换配置
|
# todo 需替换配置
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://localhost:3306/my_db
|
url: jdbc:mysql://192.168.100.113:13306/my_db
|
||||||
username: root
|
username: root
|
||||||
password: 123456
|
password: n2kXGhGY25bFkWCH
|
||||||
# Redis 配置
|
# Redis 配置
|
||||||
# todo 需替换配置
|
# todo 需替换配置
|
||||||
redis:
|
redis:
|
||||||
@@ -29,3 +29,9 @@ mybatis-plus:
|
|||||||
configuration:
|
configuration:
|
||||||
# 生产环境关闭日志
|
# 生产环境关闭日志
|
||||||
log-impl: ''
|
log-impl: ''
|
||||||
|
|
||||||
|
minio:
|
||||||
|
endpoint: http://192.168.100.113:9000
|
||||||
|
accessKey: LAVcDlmF4PHW84aoko75
|
||||||
|
secretKey: Xr5bj08bo1WexFvJwwkXyYETWzNTUdpxxSfWzMqj
|
||||||
|
bucketName: order
|
||||||
@@ -8,9 +8,9 @@ spring:
|
|||||||
# todo 需替换配置
|
# todo 需替换配置
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://localhost:3306/my_db
|
url: jdbc:mysql://192.168.100.113:13306/my_db
|
||||||
username: root
|
username: root
|
||||||
password: 123456
|
password: n2kXGhGY25bFkWCH
|
||||||
# Redis 配置
|
# Redis 配置
|
||||||
# todo 需替换配置
|
# todo 需替换配置
|
||||||
redis:
|
redis:
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ spring:
|
|||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://192.168.100.113:13306/my_db
|
url: jdbc:mysql://192.168.100.113:13306/my_db
|
||||||
username: root
|
username: my_db
|
||||||
password: n2kXGhGY25bFkWCH
|
password: n2kXGhGY25bFkWCH
|
||||||
# Redis 配置
|
# Redis 配置
|
||||||
# todo 需替换配置,然后取消注释
|
# todo 需替换配置,然后取消注释
|
||||||
@@ -84,14 +84,8 @@ wx:
|
|||||||
appSecret: xxx
|
appSecret: xxx
|
||||||
# 对象存储
|
# 对象存储
|
||||||
# todo 需替换配置
|
# todo 需替换配置
|
||||||
cos:
|
|
||||||
client:
|
|
||||||
accessKey: xxx
|
|
||||||
secretKey: xxx
|
|
||||||
region: xxx
|
|
||||||
bucket: xxx
|
|
||||||
minio:
|
minio:
|
||||||
endpoint: http://192.168.100.113:9000
|
endpoint: http://192.168.100.113:9000
|
||||||
accessKey: an3QBebaTB4N0CbIWXCm
|
accessKey: LAVcDlmF4PHW84aoko75
|
||||||
secretKey: yEEQKNw1WzBjBEgdCrVSe3AFT7ktzkrxzpHH3MZl
|
secretKey: Xr5bj08bo1WexFvJwwkXyYETWzNTUdpxxSfWzMqj
|
||||||
bucketName: order
|
bucketName: order
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
package com.yupi.springbootinit.esdao;
|
|
||||||
|
|
||||||
import com.yupi.springbootinit.model.dto.post.PostEsDTO;
|
|
||||||
import com.yupi.springbootinit.model.dto.post.PostQueryRequest;
|
|
||||||
import com.yupi.springbootinit.model.entity.Post;
|
|
||||||
import com.yupi.springbootinit.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 <a href="https://github.com/liyupi">程序员鱼皮</a>
|
|
||||||
* @from <a href="https://yupi.icu">编程导航知识星球</a>
|
|
||||||
*/
|
|
||||||
@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<Post> page =
|
|
||||||
postService.searchFromEs(postQueryRequest);
|
|
||||||
System.out.println(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testSelect() {
|
|
||||||
System.out.println(postEsDao.count());
|
|
||||||
Page<PostEsDTO> PostPage = postEsDao.findAll(
|
|
||||||
PageRequest.of(0, 5, Sort.by("createTime")));
|
|
||||||
List<PostEsDTO> 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> postEsDTO = postEsDao.findById(1L);
|
|
||||||
System.out.println(postEsDTO);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testCount() {
|
|
||||||
System.out.println(postEsDao.count());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testFindByCategory() {
|
|
||||||
List<PostEsDTO> postEsDaoTestList = postEsDao.findByUserId(1L);
|
|
||||||
System.out.println(postEsDaoTestList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package com.yupi.springbootinit.manager;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cos 操作测试
|
|
||||||
*
|
|
||||||
* @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
|
||||||
* @from <a href="https://yupi.icu">编程导航知识星球</a>
|
|
||||||
*/
|
|
||||||
@SpringBootTest
|
|
||||||
class CosManagerTest {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private CosManager cosManager;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void putObject() {
|
|
||||||
cosManager.putObject("test", "test.json");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package com.yupi.springbootinit.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 com.yupi.springbootinit.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 <a href="https://github.com/liyupi">程序员鱼皮</a>
|
|
||||||
* @from <a href="https://yupi.icu">编程导航知识星球</a>
|
|
||||||
*/
|
|
||||||
@SpringBootTest
|
|
||||||
class PostFavourMapperTest {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private PostFavourMapper postFavourMapper;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void listUserFavourPostByPage() {
|
|
||||||
IPage<Post> page = new Page<>(2, 1);
|
|
||||||
QueryWrapper<Post> queryWrapper = new QueryWrapper<>();
|
|
||||||
queryWrapper.eq("id", 1);
|
|
||||||
queryWrapper.like("content", "a");
|
|
||||||
IPage<Post> result = postFavourMapper.listFavourPostByPage(page, queryWrapper, 1);
|
|
||||||
Assertions.assertNotNull(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package com.yupi.springbootinit.mapper;
|
|
||||||
|
|
||||||
import com.yupi.springbootinit.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 <a href="https://github.com/liyupi">程序员鱼皮</a>
|
|
||||||
* @from <a href="https://yupi.icu">编程导航知识星球</a>
|
|
||||||
*/
|
|
||||||
@SpringBootTest
|
|
||||||
class PostMapperTest {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private PostMapper postMapper;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void listPostWithDelete() {
|
|
||||||
List<Post> postList = postMapper.listPostWithDelete(new Date());
|
|
||||||
Assertions.assertNotNull(postList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package com.yupi.springbootinit.service;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import com.yupi.springbootinit.model.entity.Post;
|
|
||||||
import com.yupi.springbootinit.model.entity.User;
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 帖子收藏服务测试
|
|
||||||
*
|
|
||||||
* @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
|
||||||
* @from <a href="https://yupi.icu">编程导航知识星球</a>
|
|
||||||
*/
|
|
||||||
@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<Post> postQueryWrapper = new QueryWrapper<>();
|
|
||||||
postQueryWrapper.eq("id", 1L);
|
|
||||||
postFavourService.listFavourPostByPage(Page.of(0, 1), postQueryWrapper, loginUser.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package com.yupi.springbootinit.service;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import com.yupi.springbootinit.model.dto.post.PostQueryRequest;
|
|
||||||
import com.yupi.springbootinit.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 <a href="https://github.com/liyupi">程序员鱼皮</a>
|
|
||||||
* @from <a href="https://yupi.icu">编程导航知识星球</a>
|
|
||||||
*/
|
|
||||||
@SpringBootTest
|
|
||||||
class PostServiceTest {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private PostService postService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void searchFromEs() {
|
|
||||||
PostQueryRequest postQueryRequest = new PostQueryRequest();
|
|
||||||
postQueryRequest.setUserId(1L);
|
|
||||||
Page<Post> postPage = postService.searchFromEs(postQueryRequest);
|
|
||||||
Assertions.assertNotNull(postPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package com.yupi.springbootinit.service;
|
|
||||||
|
|
||||||
import com.yupi.springbootinit.model.entity.User;
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 帖子点赞服务测试
|
|
||||||
*
|
|
||||||
* @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
|
||||||
* @from <a href="https://yupi.icu">编程导航知识星球</a>
|
|
||||||
*/
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package com.yupi.springbootinit.service;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户服务测试
|
|
||||||
*
|
|
||||||
* @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
|
||||||
* @from <a href="https://yupi.icu">编程导航知识星球</a>
|
|
||||||
*/
|
|
||||||
@SpringBootTest
|
|
||||||
public class UserServiceTest {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private UserService userService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void userRegister() {
|
|
||||||
String userAccount = "yupi";
|
|
||||||
String userPassword = "";
|
|
||||||
String checkPassword = "123456";
|
|
||||||
try {
|
|
||||||
long result = userService.userRegister(userAccount, userPassword, checkPassword);
|
|
||||||
Assertions.assertEquals(-1, result);
|
|
||||||
userAccount = "yu";
|
|
||||||
result = userService.userRegister(userAccount, userPassword, checkPassword);
|
|
||||||
Assertions.assertEquals(-1, result);
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package com.yupi.springbootinit.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 <a href="https://github.com/liyupi">程序员鱼皮</a>
|
|
||||||
* @from <a href="https://yupi.icu">编程导航知识星球</a>
|
|
||||||
*/
|
|
||||||
@SpringBootTest
|
|
||||||
public class EasyExcelTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void doImport() throws FileNotFoundException {
|
|
||||||
File file = ResourceUtils.getFile("classpath:test_excel.xlsx");
|
|
||||||
List<Map<Integer, String>> list = EasyExcel.read(file)
|
|
||||||
.excelType(ExcelTypeEnum.XLSX)
|
|
||||||
.sheet()
|
|
||||||
.headRowNumber(0)
|
|
||||||
.doReadSync();
|
|
||||||
System.out.println(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user