feat(grouping): 新增分组功能并优化 Markdown 文件操作
- 新增分组实体、控制器、服务和映射器 - 实现分组创建、获取、更新和删除接口 - 优化 Markdown 文件创建、获取和删除接口- 新增全局异常处理和日志记录 - 更新数据库表结构和字段类型 - 重构前端页面,支持分组和 Markdown 文件展示
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
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;
|
||||
@@ -9,6 +10,9 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "markdown接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/markdown")
|
||||
@@ -17,6 +21,13 @@ 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)
|
||||
@@ -32,20 +43,20 @@ public class MarkdownController {
|
||||
|
||||
@Operation(summary = "创建markdown文件")
|
||||
@Parameters({
|
||||
@Parameter(name = "userId", description = "用户id",required = true),
|
||||
@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 ResponseEntity<MarkdownFile> createMarkdown(
|
||||
@RequestParam Long userId,
|
||||
@RequestParam Long groupingId,
|
||||
@RequestParam String title,
|
||||
@RequestParam String fileName,
|
||||
@RequestBody String content) {
|
||||
|
||||
MarkdownFile file = markdownFileService.createMarkdownFile(
|
||||
userId, title, fileName, content);
|
||||
groupingId, title, fileName, content);
|
||||
|
||||
return ResponseEntity.ok(file);
|
||||
}
|
||||
@@ -67,4 +78,28 @@ public class MarkdownController {
|
||||
}
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有Markdown文件")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<MarkdownFile>> getAllMarkdownFiles() {
|
||||
// 固定用户ID=1,因为是个人笔记
|
||||
List<MarkdownFile> files = markdownFileService.getAllMarkdownFiles();
|
||||
return ResponseEntity.ok(files);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除Markdown文件")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteMarkdown(@PathVariable Long id) {
|
||||
if (markdownFileService.deleteMarkdownFile(id)) {
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "根据分组ID获取Markdown文件")
|
||||
@GetMapping("/grouping/{groupingId}")
|
||||
public ResponseEntity<List<MarkdownFile>> getFilesByGroupingId(@PathVariable String groupingId) {
|
||||
List<MarkdownFile> files = markdownFileService.getFilesByGroupingId(groupingId);
|
||||
return ResponseEntity.ok(files);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user