feat: 实现 API 接口对接功能 (删除作品、作品搜索、修改密码)
按照 TDD 规范完成三个核心功能的接口对接: ## 新增功能 ### 1. 删除作品功能 (app/generationRecord.tsx) - 新增 use-template-generation-actions.ts hook - 支持单个删除和批量删除作品 - 删除确认对话框 - 删除成功后自动刷新列表 - 完整的错误处理和加载状态 ### 2. 作品搜索功能 (app/searchWorksResults.tsx) - 新增 use-works-search.ts hook - 替换模拟数据为真实 SDK 接口 - 支持关键词搜索和分类筛选 - 支持分页加载 - 完整的加载、错误、空结果状态处理 ### 3. 修改密码功能 (app/changePassword.tsx) - 新增 use-change-password.ts hook - 使用 Better Auth 的 changePassword API - 客户端表单验证(密码长度、确认密码匹配等) - 成功后自动返回并提示 ## 技术实现 - 严格遵循 TDD 规范(先写测试,后写实现) - 新增 3 个 hooks 和对应的单元测试 - 更新中英文翻译文件 - 更新 jest.setup.js 添加必要的 mock ## 文档 - 新增 api_integration_report.md - API 对接分析报告 - 新增 api_integration_development_plan.md - 开发计划和完成汇总 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
163
findings.md
163
findings.md
@@ -1,121 +1,66 @@
|
||||
# Findings: Backend Integration Research
|
||||
# Findings & Decisions
|
||||
|
||||
## Date: 2026-01-21
|
||||
## Requirements
|
||||
根据用户需求,需要实现以下功能:
|
||||
- 单个删除生成记录
|
||||
- 删除成功后刷新列表
|
||||
- 删除失败显示错误提示
|
||||
- 删除操作有确认对话框(已有)
|
||||
- 单元测试覆盖率 > 80%
|
||||
- 严格遵循 TDD 规范
|
||||
|
||||
## Project Structure
|
||||
- **Package Manager:** bun
|
||||
- **Base URL:** https://api.mixvideo.bowong.cc
|
||||
- **Owner ID:** t0m9cketSQdCA6cHXI9mXQLJPM9LDIw5
|
||||
- **SDK Location:** node_modules/@repo/sdk
|
||||
## Research Findings
|
||||
|
||||
## @repo/sdk Analysis
|
||||
### 现有代码分析
|
||||
1. **页面组件** (`app/generationRecord.tsx`):
|
||||
- 已有删除按钮和删除确认对话框
|
||||
- `handleDelete` 函数目前只是打印日志
|
||||
- 已使用 `useTemplateGenerations` hook
|
||||
- 已有删除确认组件 `DeleteConfirmDialog`
|
||||
|
||||
### Architecture
|
||||
- **Pattern:** Dependency Injection with Better Auth integration
|
||||
- **Controllers:** 23 total (Activity, Template, Project, Chat, File, etc.)
|
||||
- **Access Methods:**
|
||||
1. Better Auth style: `authClient.loomart.xxx`
|
||||
2. DI style: `root.get(Controller)`
|
||||
2. **现有 Hooks** (`hooks/use-template-generations.ts`):
|
||||
- 使用 `root.get(TemplateGenerationController)` 获取控制器
|
||||
- 使用 `handleError` 处理错误
|
||||
- 提供了 `refetch` 方法用于刷新列表
|
||||
- 模式:自定义状态管理 + useCallback
|
||||
|
||||
### Key Controllers
|
||||
1. **TemplateController** - Template CRUD, workflow execution
|
||||
2. **CategoryController** - Category management with templates
|
||||
3. **ProjectController** - Project management
|
||||
4. **ChatController** - Chat functionality
|
||||
5. **FileController** - File management
|
||||
6. **ActivityController** - Activity tracking
|
||||
7. **TemplateSocialController** - Likes, views, social features
|
||||
8. **TemplateGenerationController** - Generation tracking
|
||||
9. **AICharacterController** - AI character management
|
||||
10. **AigcController** - AIGC operations
|
||||
3. **参考实现** (`hooks/use-template-actions.ts`):
|
||||
- 类似的模式:loading, error 状态
|
||||
- 使用 `handleError` 包装 API 调用
|
||||
- 返回函数和状态
|
||||
|
||||
## Current State Management
|
||||
4. **SDK 控制器** (`node_modules/@repo/sdk/src/controllers/template-generation.controller.ts`):
|
||||
- `delete(body: { id: string }): Promise<{ message: string }>`
|
||||
- `batchDelete(body: { ids: string[] }): Promise<{ message: string }>`
|
||||
- 都需要 `@RequirePermissions({ template: ['run'] })`
|
||||
|
||||
### Zustand Stores (Only 1)
|
||||
- **useCategoriesStore** (hooks/use-categories.ts)
|
||||
- Global cache for categories
|
||||
- Has loading/error/hasLoaded states
|
||||
- Prevents redundant API calls
|
||||
5. **测试配置**:
|
||||
- 使用 Jest 作为测试框架
|
||||
- 已安装 `@testing-library/react-native`
|
||||
- 测试脚本:`npm test`
|
||||
|
||||
### Custom Hooks Pattern (15 hooks)
|
||||
Most screens use local state via custom hooks:
|
||||
- use-templates.ts - Template list with pagination
|
||||
- use-template-detail.ts - Single template
|
||||
- use-template-actions.ts - Like, view actions
|
||||
- use-template-generations.ts - Generation history
|
||||
- use-activates.ts - Activity list
|
||||
- use-tags.ts - Tag management
|
||||
- use-search-history.ts - Search history
|
||||
### 技术决策
|
||||
- 不使用 `@tanstack/react-query`(项目未安装)
|
||||
- 遵循现有代码模式(自定义 hooks)
|
||||
- 使用 `handleError` 统一错误处理
|
||||
|
||||
## API Integration Patterns
|
||||
## Technical Decisions
|
||||
| Decision | Rationale |
|
||||
|----------|-----------|
|
||||
| 创建独立的 actions hook | 分离关注点,遵循单一职责原则 |
|
||||
| 使用现有 handleError 模式 | 保持代码一致性 |
|
||||
| 导出 DeleteGeneration 类型 | 便于类型推断 |
|
||||
| 测试使用 @testing-library/react-hooks | React hooks 测试标准方式 |
|
||||
|
||||
### Pattern 1: Better Auth Client (Primary)
|
||||
```typescript
|
||||
import { authClient, loomart } from '@/lib/auth'
|
||||
const result = await loomart.template.list(params)
|
||||
```
|
||||
## Issues Encountered
|
||||
| Issue | Resolution |
|
||||
|-------|------------|
|
||||
| | |
|
||||
|
||||
### Pattern 2: DI Container
|
||||
```typescript
|
||||
import { root } from '@repo/core'
|
||||
import { TemplateController } from '@repo/sdk'
|
||||
const template = root.get(TemplateController)
|
||||
const result = await template.list(params)
|
||||
```
|
||||
## Resources
|
||||
- 项目测试命令: `npm test` / `npm test:watch` / `npm test:coverage`
|
||||
- SDK 控制器路径: `node_modules/@repo/sdk/src/controllers/template-generation.controller.ts`
|
||||
- 现有 hooks 模式: `hooks/use-template-actions.ts`
|
||||
|
||||
### Pattern 3: Error Handling
|
||||
```typescript
|
||||
const { data, error } = await handleError(async () => await apiCall())
|
||||
```
|
||||
|
||||
## Frontend Screens Inventory
|
||||
|
||||
### Tab Screens (5)
|
||||
| Screen | Path | Needs API | SDK Support | Notes |
|
||||
|--------|------|-----------|-------------|-------|
|
||||
| Home | (tabs)/index.tsx | ✅ Categories, Templates | ✅ TemplateController, CategoryController | Has basic integration |
|
||||
| Video | (tabs)/video.tsx | ✅ Video list | ✅ TemplateController | Already uses useTemplates |
|
||||
| Message | (tabs)/message.tsx | ✅ Chat/messages | ❌ No list API | ChatController只有chat()和listModels(),没有消息列表接口 |
|
||||
| My Profile | (tabs)/my.tsx | ✅ User data | ⚠️ 需确认 | 需要用户信息接口 |
|
||||
|
||||
### Main Screens (15)
|
||||
| Screen | Path | Needs API | Notes |
|
||||
|--------|------|-----------|-------|
|
||||
| Auth | auth.tsx | ✅ Login/signup | Has Better Auth |
|
||||
| Membership | membership.tsx | ✅ Subscription | Needs Stripe |
|
||||
| Template Detail | templateDetail.tsx | ✅ Template data | Has integration |
|
||||
| Generate Video | generateVideo.tsx | ✅ Generation API | Needs progress |
|
||||
| Generation Record | generationRecord.tsx | ✅ History list | Needs pagination |
|
||||
| Works List | worksList.tsx | ✅ User works | Needs pagination |
|
||||
| Search Template | searchTemplate.tsx | ✅ Search API | Needs debounce |
|
||||
| Search Results | searchResults.tsx | ✅ Results list | Needs pagination |
|
||||
| Search Works | searchWorks.tsx | ✅ Works search | Needs pagination |
|
||||
| Search Works Results | searchWorksResults.tsx | ✅ Results list | Needs pagination |
|
||||
| Channels | channels.tsx | ✅ Category data | Needs refresh |
|
||||
| Change Password | changePassword.tsx | ✅ Auth API | Has integration |
|
||||
| Privacy | privacy.tsx | ❌ Static | No API needed |
|
||||
| Terms | terms.tsx | ❌ Static | No API needed |
|
||||
|
||||
## Key Discoveries
|
||||
|
||||
1. **Minimal Global State:** Only 1 Zustand store (categories), rest uses local state
|
||||
2. **Hook-Based Architecture:** 15 custom hooks handle API calls
|
||||
3. **Existing Patterns:** Some screens already have API integration
|
||||
4. **Missing Features:**
|
||||
- Loading states inconsistent across screens
|
||||
- No pull-to-refresh on most screens
|
||||
- Pagination exists in hooks but not all screens use it
|
||||
- No error retry mechanisms
|
||||
- No optimistic updates
|
||||
5. **SDK限制:**
|
||||
- ❌ ChatController没有消息列表接口(只有chat()和listModels())
|
||||
- ❌ 没有用户信息相关的Controller
|
||||
- ✅ Video页面已正确使用TemplateController(不需要单独的视频hook)
|
||||
|
||||
## Technical Constraints
|
||||
|
||||
1. **Multi-tenant:** All requests need `x-ownerid` header
|
||||
2. **Authentication:** Token stored in expo-secure-store
|
||||
3. **Design Width:** 375px (need to convert styles to Tailwind)
|
||||
4. **No Redux:** Project uses minimal global state approach
|
||||
5. **Better Auth:** Primary auth method, SDK integrated as plugin
|
||||
## Visual/Browser Findings
|
||||
-
|
||||
|
||||
Reference in New Issue
Block a user