feat(biji-houdaun): 支持 Markdown 文件上传、预览、编辑和创建
- 新增 Markdown 文件预览功能 - 更新 Markdown 文件创建和编辑接口,使用 Long 类型的 ID - 优化图片上传接口,支持 Long 类型的用户 ID 和 Markdown ID - 重构 MarkdownFileService接口,增加获取 Markdown 文件的方法 - 修改 MarkdownFileServiceImpl 实现类,支持新的 Markdown 文件操作
This commit is contained in:
@@ -31,8 +31,8 @@ public class ImageController {
|
||||
})
|
||||
@PostMapping
|
||||
public ResponseEntity<Image> uploadImage(
|
||||
@RequestParam Integer userId,
|
||||
@RequestParam(required = false) Integer markdownId,
|
||||
@RequestParam Long userId,
|
||||
@RequestParam(required = false) Long markdownId,
|
||||
@RequestParam("file") MultipartFile file) {
|
||||
|
||||
try {
|
||||
@@ -42,4 +42,4 @@ public class ImageController {
|
||||
return ResponseEntity.status(500).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,19 @@ public class MarkdownController {
|
||||
@Autowired
|
||||
private MarkdownFileService markdownFileService;
|
||||
|
||||
@Operation(summary = "预览markdown文件")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "文件ID", required = true)
|
||||
})
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<String> getMarkdownContent(@PathVariable Long id) {
|
||||
MarkdownFile file = markdownFileService.getMarkdownById(id);
|
||||
if (file != null) {
|
||||
return ResponseEntity.ok(file.getContent());
|
||||
}
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "创建markdown文件")
|
||||
@Parameters({
|
||||
@Parameter(name = "userId", description = "用户id",required = true),
|
||||
@@ -26,7 +39,7 @@ public class MarkdownController {
|
||||
})
|
||||
@PostMapping
|
||||
public ResponseEntity<MarkdownFile> createMarkdown(
|
||||
@RequestParam Integer userId,
|
||||
@RequestParam Long userId,
|
||||
@RequestParam String title,
|
||||
@RequestParam String fileName,
|
||||
@RequestBody String content) {
|
||||
@@ -44,7 +57,7 @@ public class MarkdownController {
|
||||
})
|
||||
@PostMapping("/{id}")
|
||||
public ResponseEntity<MarkdownFile> updateMarkdown(
|
||||
@PathVariable Integer id,
|
||||
@PathVariable Long id,
|
||||
@RequestBody String content) {
|
||||
|
||||
MarkdownFile file = markdownFileService.updateMarkdownContent(id, content);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
9
doc/111.md
Normal file
9
doc/111.md
Normal file
@@ -0,0 +1,9 @@
|
||||
vite+vue3.js怎么支持markdown文件的上传,预览、编辑、创建呢?我使用springboot3作为后端
|
||||
,前端怎么创建markdown文件并且编写后传给后端,是传文件还是直接传字符保存到数据库中的,给我详细的代码,并且带上注释
|
||||
|
||||
|
||||
1、首先分析本项目的后端,了解项目所使用的技术和版本,之后查看项目中各个部分的代码,了解各个部分的功能和实现方式。
|
||||
|
||||
2、分析好项目,我要实现其中的markdown文件的上传,预览、编辑、创建,并且是带有图片的,能在前端实现上传,预览、编辑、创建等功能,要符合项目用到的技术、版本和业务,不要修改无关的文件。 要求使用MCP服务器中的context7工具来查询最新的文档
|
||||
|
||||
3、现在开始实现上述的功能,不要去分析前端,现在先弄好后端,先实现上传、预览、编辑、创建等功能,要符合项目用到的技术、版本和业务,不要修改无关的文件。 要求使用MCP服务器中的context7工具用来查询最新的文档,确保我想要的功能是符合项目的要求,并且是符合项目的业务逻辑。
|
||||
Reference in New Issue
Block a user