readful/lib/services/bookshelf_repository.dart
ddshi 02010ff972 feat: 完成数据持久化阶段并规划UI开发
📊 数据持久化阶段完成:
- 完成4个数据模型的Hive集成(Book, Bookshelf, Bookmark, Highlight)
- 实现4个Repository数据访问层
- 生成5个TypeAdapter自动序列化文件
- 完成所有模型的CRUD操作和测试验证

📚 项目文档更新:
- 新增数据持久化阶段完成总结文档
- 更新CLAUDE.md项目主文档
- 完善项目结构说明和开发进度

🚀 UI开发阶段规划:
- 定义产品定位:类似微信读书的Material Design电子书阅读器
- 制定4阶段开发计划:UI基础架构→顶部导航→首页内容→数据集成
- 明确页面结构:底部Tab导航(首页/书库/统计/我的)
- 规划核心功能:搜索、导入、最近阅读、摘录列表

🎯 下一里程碑:
- 开始UI基础架构搭建
- 实现底部Tab导航和Material Design主题系统

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-01 17:34:50 +08:00

64 lines
1.7 KiB
Dart

import '../models/bookshelf.dart';
import 'database_service.dart';
class BookshelfRepository {
final DatabaseService _databaseService = DatabaseService.instance;
/// 获取所有书架
Future<List<Bookshelf>> getAllBookshelves() async {
try {
final bookshelvesBox = _databaseService.getBookshelvesBox();
return bookshelvesBox.values.toList();
} catch (e) {
print('❌ 获取所有书架失败: $e');
rethrow;
}
}
/// 根据ID获取书架
Future<Bookshelf?> getBookshelfById(String id) async {
try {
final bookshelvesBox = _databaseService.getBookshelvesBox();
return bookshelvesBox.get(id);
} catch (e) {
print('❌ 根据ID获取书架失败: $e');
rethrow;
}
}
/// 添加新书架
Future<void> addBookshelf(Bookshelf bookshelf) async {
try {
final bookshelvesBox = _databaseService.getBookshelvesBox();
await bookshelvesBox.put(bookshelf.id, bookshelf);
print('✅ 书架添加成功: ${bookshelf.name}');
} catch (e) {
print('❌ 添加书架失败: $e');
rethrow;
}
}
/// 更新书架信息
Future<void> updateBookshelf(Bookshelf bookshelf) async {
try {
final bookshelvesBox = _databaseService.getBookshelvesBox();
await bookshelvesBox.put(bookshelf.id, bookshelf);
print('✅ 书架更新成功: ${bookshelf.name}');
} catch (e) {
print('❌ 更新书架失败: $e');
rethrow;
}
}
/// 删除书架
Future<void> deleteBookshelf(String id) async {
try {
final bookshelvesBox = _databaseService.getBookshelvesBox();
await bookshelvesBox.delete(id);
print('✅ 书架删除成功: $id');
} catch (e) {
print('❌ 删除书架失败: $e');
rethrow;
}
}
}