feat(biji): 添加最近更新笔记功能
- 在前端添加 getRecentFiles API 接口 - 在后端添加 getRecentFiles 接口和相关服务方法 - 实现最近更新笔记的获取和展示 - 优化首页初始化逻辑,加载最近更新笔记
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package com.test.bijihoudaun.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
/**
|
||||
* 添加分页插件
|
||||
*/
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.SQLITE));
|
||||
return interceptor;
|
||||
}
|
||||
}
|
||||
@@ -94,4 +94,11 @@ public class MarkdownController {
|
||||
}
|
||||
return R.fail("文件未找到或更新失败");
|
||||
}
|
||||
|
||||
@Operation(summary = "获取最近更新的笔记")
|
||||
@GetMapping("/recent")
|
||||
public R<List<MarkdownFile>> getRecentFiles() {
|
||||
List<MarkdownFile> files = markdownFileService.getRecentFiles(10);
|
||||
return R.success(files);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,4 +57,11 @@ public interface MarkdownFileService extends IService<MarkdownFile> {
|
||||
* @return 更新后的文件对象
|
||||
*/
|
||||
MarkdownFile updateMarkdownTitle(Long id, String title);
|
||||
|
||||
/**
|
||||
* 获取最近更新的笔记
|
||||
* @param limit 数量
|
||||
* @return 文件列表
|
||||
*/
|
||||
List<MarkdownFile> getRecentFiles(int limit);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.test.bijihoudaun.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.test.bijihoudaun.entity.MarkdownFile;
|
||||
import com.test.bijihoudaun.mapper.MarkdownFileMapper;
|
||||
@@ -86,4 +86,12 @@ public class MarkdownFileServiceImpl
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MarkdownFile> getRecentFiles(int limit) {
|
||||
Page<MarkdownFile> page = new Page<>(1, limit);
|
||||
QueryWrapper<MarkdownFile> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.orderByDesc("updated_at");
|
||||
return this.page(page, queryWrapper).getRecords();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user