- 新增 updateMarkdown API 接口,用于更新 Markdown 文件内容 - 在 HomePage 组件中集成 Markdown 编辑器,支持文件编辑和保存 - 优化 MarkdownEditor 组件,支持内容预览和编辑切换 - 更新后端 MarkdownController,增加文件更新相关处理
104 lines
3.5 KiB
Java
104 lines
3.5 KiB
Java
package com.test.bijihoudaun.controller;
|
|
|
|
import com.test.bijihoudaun.common.response.R;
|
|
import com.test.bijihoudaun.entity.MarkdownFile;
|
|
import com.test.bijihoudaun.service.MarkdownFileService;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
import io.swagger.v3.oas.annotations.Parameters;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
|
|
@Tag(name = "markdown接口")
|
|
@RestController
|
|
@RequestMapping("/api/markdown")
|
|
public class MarkdownController {
|
|
|
|
@Autowired
|
|
private MarkdownFileService markdownFileService;
|
|
|
|
@Operation(summary = "测试")
|
|
@GetMapping("/test")
|
|
public R<List<MarkdownFile>> test() {
|
|
List<MarkdownFile> test = markdownFileService.test();
|
|
return R.success(test);
|
|
}
|
|
|
|
@Operation(summary = "预览markdown文件")
|
|
@Parameters({
|
|
@Parameter(name = "id", description = "文件ID", required = true)
|
|
})
|
|
@GetMapping("/{id}")
|
|
public R<String> getMarkdownContent(@PathVariable Long id) {
|
|
MarkdownFile file = markdownFileService.getMarkdownById(id);
|
|
if (file != null) {
|
|
return R.success(file.getContent());
|
|
}
|
|
return R.fail();
|
|
}
|
|
|
|
@Operation(summary = "创建markdown文件")
|
|
@Parameters({
|
|
@Parameter(name = "groupingId", description = "分组id",required = true),
|
|
@Parameter(name = "title", description = "标题",required = true),
|
|
@Parameter(name = "fileName", description = "文件名",required = true),
|
|
@Parameter(name = "content", description = "内容",required = true)
|
|
})
|
|
@PostMapping
|
|
public R<MarkdownFile> createMarkdown(
|
|
@RequestParam Long groupingId,
|
|
@RequestParam String title,
|
|
@RequestParam String fileName,
|
|
@RequestBody String content) {
|
|
|
|
MarkdownFile file = markdownFileService.createMarkdownFile(
|
|
groupingId, title, fileName, content);
|
|
|
|
return R.success(file);
|
|
}
|
|
|
|
@Operation(summary = "更新Markdown文件")
|
|
@Parameters({
|
|
@Parameter(name = "id", description = "Markdown文件ID", required = true),
|
|
@Parameter(name = "content", description = "Markdown文件内容", required = true)
|
|
})
|
|
@PostMapping("/{id}")
|
|
public R<MarkdownFile> updateMarkdown(
|
|
@PathVariable String id,
|
|
String content) {
|
|
long l = Long.parseLong(id);
|
|
MarkdownFile file = markdownFileService.updateMarkdownContent(l, content);
|
|
|
|
if (file != null) {
|
|
return R.success(file);
|
|
}
|
|
return R.fail();
|
|
}
|
|
|
|
@Operation(summary = "获取所有Markdown文件")
|
|
@GetMapping
|
|
public R<List<MarkdownFile>> getAllMarkdownFiles() {
|
|
List<MarkdownFile> files = markdownFileService.getAllMarkdownFiles();
|
|
return R.success(files);
|
|
}
|
|
|
|
@Operation(summary = "删除Markdown文件")
|
|
@DeleteMapping("/{id}")
|
|
public R<Void> deleteMarkdown(@PathVariable Long id) {
|
|
if (markdownFileService.deleteMarkdownFile(id)) {
|
|
return R.success();
|
|
}
|
|
return R.fail();
|
|
}
|
|
|
|
@Operation(summary = "根据分组ID获取Markdown文件")
|
|
@GetMapping("/grouping/{groupingId}")
|
|
public R<List<MarkdownFile>> getFilesByGroupingId(@PathVariable String groupingId) {
|
|
List<MarkdownFile> files = markdownFileService.getFilesByGroupingId(groupingId);
|
|
return R.success(files);
|
|
}
|
|
}
|