feat(note): 新增笔记创建和编辑功能
- 实现了笔记创建和编辑的前端逻辑 - 更新了相关的后端接口和数据库操作 - 优化了分组获取和展示逻辑 -调整了 Markdown 文件更新接口
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.test.bijihoudaun.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.test.bijihoudaun.common.response.R;
|
||||
import com.test.bijihoudaun.entity.Grouping;
|
||||
import com.test.bijihoudaun.service.GroupingService;
|
||||
@@ -29,14 +30,14 @@ public class GroupingController {
|
||||
|
||||
@Operation(summary = "获取全部分组")
|
||||
@Parameters({
|
||||
@Parameter(name = "parentId", description = "0是一级,其他的是看它的父级id", required = true)
|
||||
@Parameter(name = "parentId", description = "0是一级,其他的是看它的父级id", required = false)
|
||||
})
|
||||
@GetMapping
|
||||
public R<List<Grouping>> getAllGroupings(String parentId) {
|
||||
if (parentId == null) {
|
||||
return R.fail("参数不能为空");
|
||||
public R<List<Grouping>> getAllGroupings(@RequestParam(required = false) String parentId) {
|
||||
Long l= null;
|
||||
if (StrUtil.isNotEmpty(parentId)) {
|
||||
l = Long.parseLong(parentId);
|
||||
}
|
||||
long l = Long.parseLong(parentId);
|
||||
List<Grouping> groupings = groupingService.getAllGroupings(l);
|
||||
return R.success(groupings);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "markdown接口")
|
||||
@@ -61,21 +62,10 @@ public class MarkdownController {
|
||||
}
|
||||
|
||||
@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();
|
||||
@PostMapping("/updateMarkdown")
|
||||
public R<MarkdownFile> updateMarkdown(@RequestBody MarkdownFile markdownFile) {
|
||||
MarkdownFile file = markdownFileService.updateMarkdownContent(markdownFile);
|
||||
return R.success(file);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有Markdown文件")
|
||||
|
||||
@@ -18,11 +18,9 @@ public interface MarkdownFileService extends IService<MarkdownFile> {
|
||||
|
||||
/**
|
||||
* 更新Markdown内容
|
||||
* @param id 文件ID
|
||||
* @param content 新内容
|
||||
* @return 更新后的文件对象
|
||||
*/
|
||||
MarkdownFile updateMarkdownContent(Long id, String content);
|
||||
MarkdownFile updateMarkdownContent(MarkdownFile markdownFile);
|
||||
|
||||
/**
|
||||
* 根据ID获取Markdown文件
|
||||
|
||||
@@ -27,9 +27,11 @@ public class GroupingServiceImpl
|
||||
|
||||
@Override
|
||||
public List<Grouping> getAllGroupings(Long parentId) {
|
||||
// return groupingMapper.selectList(new LambdaQueryWrapper<Grouping>()
|
||||
// .eq(Grouping::getParentId, parentId));
|
||||
return groupingMapper.selectList(null);
|
||||
if (parentId == null){
|
||||
return groupingMapper.selectList(null);
|
||||
}
|
||||
return groupingMapper.selectList(new LambdaQueryWrapper<Grouping>()
|
||||
.eq(Grouping::getParentId, parentId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,14 +40,16 @@ public class MarkdownFileServiceImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkdownFile updateMarkdownContent(Long id, String content) {
|
||||
MarkdownFile file = this.getById(id);
|
||||
if (file != null) {
|
||||
file.setContent(content);
|
||||
file.setUpdatedAt(new Date());
|
||||
this.updateById(file);
|
||||
public MarkdownFile updateMarkdownContent(MarkdownFile markdownFile) {
|
||||
markdownFile.setUpdatedAt(new Date());
|
||||
if (markdownFile.getId() != null){
|
||||
markdownFileMapper.update(markdownFile, new QueryWrapper<MarkdownFile>().eq("id", markdownFile.getId()));
|
||||
}else {
|
||||
markdownFile.setId(snowflakeIdGenerator.nextId());
|
||||
markdownFile.setCreatedAt(new Date());
|
||||
markdownFileMapper.insert(markdownFile);
|
||||
}
|
||||
return file;
|
||||
return markdownFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user