feat(grouping): 新增分组功能并优化 Markdown 文件操作
- 新增分组实体、控制器、服务和映射器 - 实现分组创建、获取、更新和删除接口 - 优化 Markdown 文件创建、获取和删除接口- 新增全局异常处理和日志记录 - 更新数据库表结构和字段类型 - 重构前端页面,支持分组和 Markdown 文件展示
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package com.test.bijihoudaun.controller;
|
||||
|
||||
import com.test.bijihoudaun.entity.Grouping;
|
||||
import com.test.bijihoudaun.service.GroupingService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
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 = "分组接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/groupings")
|
||||
public class GroupingController {
|
||||
|
||||
@Autowired
|
||||
private GroupingService groupingService;
|
||||
|
||||
@Operation(summary = "创建分组")
|
||||
@PostMapping
|
||||
public ResponseEntity<Grouping> createGrouping(@RequestBody Grouping grouping) {
|
||||
Grouping created = groupingService.createGrouping(grouping);
|
||||
return ResponseEntity.ok(created);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取全部分组")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<Grouping>> getAllGroupings() {
|
||||
List<Grouping> groupings = groupingService.getAllGroupings();
|
||||
return ResponseEntity.ok(groupings);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新分组名称")
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<Grouping> updateGrouping(
|
||||
@PathVariable Long id,
|
||||
@RequestBody Grouping grouping) {
|
||||
grouping.setId(id);
|
||||
Grouping updated = groupingService.updateGrouping(grouping);
|
||||
return ResponseEntity.ok(updated);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除分组")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteGrouping(@PathVariable Long id) {
|
||||
groupingService.deleteGrouping(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
@@ -25,18 +25,16 @@ public class ImageController {
|
||||
|
||||
@Operation(summary = "上传图片")
|
||||
@Parameters({
|
||||
@Parameter(name = "userId", description = "用户id", required = true),
|
||||
@Parameter(name = "markdownId", description = "markdownid", required = true),
|
||||
@Parameter(name = "file", description = "图片文件", required = true)
|
||||
})
|
||||
@PostMapping
|
||||
public ResponseEntity<Image> uploadImage(
|
||||
@RequestParam Long userId,
|
||||
@RequestParam(required = false) Long markdownId,
|
||||
@RequestParam("file") MultipartFile file) {
|
||||
|
||||
try {
|
||||
Image image = imageService.uploadImage(userId, markdownId, file);
|
||||
Image image = imageService.uploadImage(markdownId, file);
|
||||
return ResponseEntity.ok(image);
|
||||
} catch (IOException e) {
|
||||
return ResponseEntity.status(500).build();
|
||||
|
||||
@@ -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