feat(biji-houdaun): 支持 Markdown 文件上传、预览、编辑和创建
- 新增 Markdown 文件预览功能 - 更新 Markdown 文件创建和编辑接口,使用 Long 类型的 ID - 优化图片上传接口,支持 Long 类型的用户 ID 和 Markdown ID - 重构 MarkdownFileService接口,增加获取 Markdown 文件的方法 - 修改 MarkdownFileServiceImpl 实现类,支持新的 Markdown 文件操作
This commit is contained in:
@@ -16,7 +16,7 @@ public interface ImageService extends IService<Image> {
|
||||
* @return 上传的图片对象
|
||||
* @throws IOException 文件操作异常
|
||||
*/
|
||||
Image uploadImage(Integer userId, Integer markdownId, MultipartFile file) throws IOException;
|
||||
Image uploadImage(Long userId, Long markdownId, MultipartFile file) throws IOException;
|
||||
|
||||
/**
|
||||
* 删除图片
|
||||
@@ -24,19 +24,19 @@ public interface ImageService extends IService<Image> {
|
||||
* @param userId 用户ID(用于权限验证)
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
boolean deleteImage(Integer id, Integer userId);
|
||||
boolean deleteImage(Long id, Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户的图片列表
|
||||
* @param userId 用户ID
|
||||
* @return 图片列表
|
||||
*/
|
||||
List<Image> getUserImages(Integer userId);
|
||||
List<Image> getUserImages(Long userId);
|
||||
|
||||
/**
|
||||
* 获取Markdown文件关联的图片
|
||||
* @param markdownId Markdown文件ID
|
||||
* @return 图片列表
|
||||
*/
|
||||
List<Image> getMarkdownImages(Integer markdownId);
|
||||
}
|
||||
List<Image> getMarkdownImages(Long markdownId);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public interface MarkdownFileService extends IService<MarkdownFile> {
|
||||
* @param content 文件内容
|
||||
* @return 创建的文件对象
|
||||
*/
|
||||
MarkdownFile createMarkdownFile(Integer userId, String title, String fileName, String content);
|
||||
MarkdownFile createMarkdownFile(Long userId, String title, String fileName, String content);
|
||||
|
||||
/**
|
||||
* 更新Markdown内容
|
||||
@@ -22,12 +22,19 @@ public interface MarkdownFileService extends IService<MarkdownFile> {
|
||||
* @param content 新内容
|
||||
* @return 更新后的文件对象
|
||||
*/
|
||||
MarkdownFile updateMarkdownContent(Integer id, String content);
|
||||
MarkdownFile updateMarkdownContent(Long id, String content);
|
||||
|
||||
/**
|
||||
* 根据ID获取Markdown文件
|
||||
* @param id 文件ID
|
||||
* @return Markdown文件对象
|
||||
*/
|
||||
MarkdownFile getMarkdownById(Long id);
|
||||
|
||||
/**
|
||||
* 获取用户的所有Markdown文件
|
||||
* @param userId 用户ID
|
||||
* @return 文件列表
|
||||
*/
|
||||
List<MarkdownFile> getUserFiles(Integer userId);
|
||||
}
|
||||
List<MarkdownFile> getUserFiles(Long userId);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ImageServiceImpl
|
||||
private String uploadDir;
|
||||
|
||||
@Override
|
||||
public Image uploadImage(Integer userId, Integer markdownId, MultipartFile file) throws IOException {
|
||||
public Image uploadImage(Long userId, Long markdownId, MultipartFile file) throws IOException {
|
||||
// 创建上传目录
|
||||
Path uploadPath = Paths.get(uploadDir);
|
||||
if (!Files.exists(uploadPath)) {
|
||||
@@ -50,7 +50,7 @@ public class ImageServiceImpl
|
||||
image.setOriginalName(originalFilename);
|
||||
image.setStoredName(storedName);
|
||||
image.setUrl("/uploads/" + storedName);
|
||||
image.setSize((int) file.getSize());
|
||||
image.setSize(file.getSize());
|
||||
image.setContentType(file.getContentType());
|
||||
image.setCreatedAt(LocalDateTime.now());
|
||||
|
||||
@@ -59,7 +59,7 @@ public class ImageServiceImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteImage(Integer id, Integer userId) {
|
||||
public boolean deleteImage(Long id, Long userId) {
|
||||
QueryWrapper<Image> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", id)
|
||||
.eq("user_id", userId);
|
||||
@@ -83,7 +83,7 @@ public class ImageServiceImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Image> getUserImages(Integer userId) {
|
||||
public List<Image> getUserImages(Long userId) {
|
||||
QueryWrapper<Image> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_id", userId)
|
||||
.orderByDesc("created_at");
|
||||
@@ -91,10 +91,10 @@ public class ImageServiceImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Image> getMarkdownImages(Integer markdownId) {
|
||||
public List<Image> getMarkdownImages(Long markdownId) {
|
||||
QueryWrapper<Image> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("markdown_id", markdownId)
|
||||
.orderByDesc("created_at");
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.test.bijihoudaun.entity.MarkdownFile;
|
||||
import com.test.bijihoudaun.mapper.MarkdownFileMapper;
|
||||
import com.test.bijihoudaun.service.MarkdownFileService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -17,7 +18,7 @@ public class MarkdownFileServiceImpl
|
||||
implements MarkdownFileService {
|
||||
|
||||
@Override
|
||||
public MarkdownFile createMarkdownFile(Integer userId, String title, String fileName, String content) {
|
||||
public MarkdownFile createMarkdownFile(Long userId, String title, String fileName, String content) {
|
||||
MarkdownFile file = new MarkdownFile();
|
||||
file.setUserId(userId);
|
||||
file.setTitle(title);
|
||||
@@ -31,7 +32,7 @@ public class MarkdownFileServiceImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkdownFile updateMarkdownContent(Integer id, String content) {
|
||||
public MarkdownFile updateMarkdownContent(Long id, String content) {
|
||||
MarkdownFile file = this.getById(id);
|
||||
if (file != null) {
|
||||
file.setContent(content);
|
||||
@@ -40,12 +41,17 @@ public class MarkdownFileServiceImpl
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkdownFile getMarkdownById(Long id) {
|
||||
return this.getById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MarkdownFile> getUserFiles(Integer userId) {
|
||||
public List<MarkdownFile> getUserFiles(Long userId) {
|
||||
QueryWrapper<MarkdownFile> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_id", userId)
|
||||
.orderByDesc("updated_at");
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user