refactor: 重构待办事项模块结构与命名
This commit is contained in:
+11
-11
@@ -314,7 +314,7 @@ const task = response.data as Task; // 避免
|
||||
```typescript
|
||||
// 使用 async/await 而非 Promise 链
|
||||
async function getTasks(): Promise<Task[]> {
|
||||
const response = await axios.get('/api/tasks');
|
||||
const response = await axios.get('/api/task');
|
||||
return response.data;
|
||||
}
|
||||
|
||||
@@ -457,7 +457,7 @@ export const useTaskStore = defineStore('tasks', () => {
|
||||
async function fetchTasks() {
|
||||
loading.value = true;
|
||||
try {
|
||||
const response = await fetch('/api/tasks');
|
||||
const response = await fetch('/api/task');
|
||||
tasks.value = await response.json();
|
||||
} catch (err) {
|
||||
error.value = 'Failed to fetch tasks';
|
||||
@@ -481,30 +481,30 @@ export const useTaskStore = defineStore('tasks', () => {
|
||||
|
||||
### 6.1 RESTful API 设计
|
||||
```csharp
|
||||
// 使用名词复数形式
|
||||
[HttpGet("tasks")]
|
||||
// 本项目的任务端点采用 Dynamic API 路由约定:/api/task(由中间件反射分发)
|
||||
[HttpGet("task")]
|
||||
public async Task<ActionResult<List<Task>>> GetTasks()
|
||||
{
|
||||
}
|
||||
|
||||
// 使用资源 ID
|
||||
[HttpGet("tasks/{id}")]
|
||||
[HttpGet("task/{id}")]
|
||||
public async Task<ActionResult<Task>> GetTask(int id)
|
||||
{
|
||||
}
|
||||
|
||||
// 使用 HTTP 方法表示操作
|
||||
[HttpPost("tasks")]
|
||||
[HttpPost("task")]
|
||||
public async Task<ActionResult<Task>> CreateTask(CreateTaskDto dto)
|
||||
{
|
||||
}
|
||||
|
||||
[HttpPut("tasks/{id}")]
|
||||
public async Task<ActionResult<Task>> UpdateTask(int id, UpdateTaskDto dto)
|
||||
[HttpPut("task")]
|
||||
public async Task<ActionResult<Task>> UpdateTask(UpdateTaskDto dto)
|
||||
{
|
||||
}
|
||||
|
||||
[HttpDelete("tasks/{id}")]
|
||||
[HttpDelete("task/{id}")]
|
||||
public async Task<ActionResult> DeleteTask(int id)
|
||||
{
|
||||
}
|
||||
@@ -563,7 +563,7 @@ return BadRequest(new ApiResponse<object>
|
||||
```
|
||||
feat(api): add task completion endpoint
|
||||
|
||||
- Add PATCH /api/tasks/{id}/complete endpoint
|
||||
- Add PATCH /api/task/{id}/toggle endpoint
|
||||
- Update task service to handle completion logic
|
||||
- Add unit tests for completion functionality
|
||||
|
||||
@@ -609,7 +609,7 @@ public class ApiIntegrationTests : IClassFixture<WebApplicationFactory<Program>>
|
||||
public async Task GetTasks_ReturnsSuccessAndCorrectContentType()
|
||||
{
|
||||
// Act
|
||||
var response = await _client.GetAsync("/api/tasks");
|
||||
var response = await _client.GetAsync("/api/task");
|
||||
|
||||
// Assert
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
+29
-20
@@ -173,22 +173,28 @@ Hua.Todo/
|
||||
- WebView 容器管理
|
||||
- 本地 HTTP 服务器启动
|
||||
|
||||
**调试与接口文档**:
|
||||
- Windows Debug 模式下,内嵌 WebServer 默认提供 Swagger UI(`{HostUrl}/swagger`)与 OpenAPI JSON(`{HostUrl}/swagger/v1/swagger.json`),用于本地接口联调。
|
||||
|
||||
**关键组件**:
|
||||
- `MauiProgram.cs`: 配置 MAUI 应用和依赖注入
|
||||
- `App.xaml.cs`: 应用程序主入口
|
||||
- `WebViewContainer`: 封装 WebView 控件
|
||||
- 平台特定服务: 快捷键、通知等
|
||||
|
||||
### 4.2 后端 API 项目 (Hua.Todo.Api)
|
||||
### 4.2 后端 API 项目 (Hua.Todo.Host)
|
||||
**职责**:
|
||||
- 提供 RESTful API 接口
|
||||
- 业务逻辑处理
|
||||
- 数据访问和持久化
|
||||
- 本地 HTTP 服务器托管
|
||||
|
||||
**接口文档**:
|
||||
- 开发环境(`ASPNETCORE_ENVIRONMENT=Development`)下提供 Swagger UI:`http://localhost:5173/swagger`(或 `https://localhost:7175/swagger`)。
|
||||
|
||||
**关键组件**:
|
||||
- `Controllers`: API 端点实现
|
||||
- `Services`: 业务逻辑服务
|
||||
- `CloudSync`: 云同步 Minimal APIs(`/auth`、`/tasks`、`/sync`、`/security`)
|
||||
- `DynamicApiMiddleware`: 任务管理等业务接口通过 Dynamic API(`/api/{service}/...`)对外暴露
|
||||
- `Data`: 数据访问层和数据库上下文
|
||||
- `Program.cs`: API 服务器配置和启动
|
||||
|
||||
@@ -220,33 +226,36 @@ Hua.Todo/
|
||||
## 5. HTTP API 设计
|
||||
|
||||
### 5.1 API 基础配置
|
||||
- **基础 URL**: `http://localhost:5000/api`
|
||||
- **基础 URL(开发三件套 / Host 模式)**: `http://localhost:5173/api`(或 `https://localhost:7175/api`)
|
||||
- **基础 URL(MAUI 内嵌模式)**: `{HostUrl}/api`(`HostUrl` 来自 `appsettings.json: WebServer.HostUrl`,默认 `http://localhost:5057`)
|
||||
- **数据格式**: JSON
|
||||
- **认证方式**: 暂无(本地应用)
|
||||
- **认证方式**: 以实际端点为准(如云同步相关端点可能需要认证)
|
||||
- **跨域配置**: 允许本地跨域请求
|
||||
|
||||
### 5.2 API 端点设计
|
||||
|
||||
#### 任务管理 API
|
||||
```
|
||||
GET /api/tasks # 获取任务列表
|
||||
GET /api/tasks/{id} # 获取单个任务
|
||||
POST /api/tasks # 创建任务
|
||||
PUT /api/tasks/{id} # 更新任务
|
||||
DELETE /api/tasks/{id} # 删除任务
|
||||
PATCH /api/tasks/{id}/complete # 标记任务完成
|
||||
GET /api/task # 获取任务列表(默认:全部)
|
||||
GET /api/task/active # 获取未完成任务
|
||||
GET /api/task/completed # 获取已完成任务
|
||||
GET /api/task/{id} # 获取单个任务
|
||||
POST /api/task # 创建任务
|
||||
PUT /api/task # 更新任务(通过 Body 内的 id 定位)
|
||||
DELETE /api/task/{id} # 删除任务
|
||||
PATCH /api/task/{id}/toggle # 切换完成状态
|
||||
GET /api/task/{parentTaskId}/subtasks # 获取子任务列表
|
||||
```
|
||||
|
||||
#### 设置管理 API
|
||||
#### 云同步 API(Host 模式)
|
||||
```
|
||||
GET /api/settings # 获取设置
|
||||
PUT /api/settings # 更新设置
|
||||
```
|
||||
|
||||
#### 同步 API
|
||||
```
|
||||
POST /api/sync/pull # 拉取远程数据
|
||||
POST /api/sync/push # 推送本地数据
|
||||
POST /auth/bootstrap # 初始化管理员(仅首次)
|
||||
POST /auth/login # 登录
|
||||
POST /auth/step-up # 二次验证(提升权限)
|
||||
GET /tasks/ # 获取云端任务(只读)
|
||||
POST /sync/ # 推送/拉取合并同步
|
||||
GET /security/policy # 获取安全策略
|
||||
PUT /security/policy # 更新安全策略
|
||||
```
|
||||
|
||||
## 6. 数据库设计
|
||||
|
||||
+8
-1
@@ -12,9 +12,16 @@
|
||||
### v1.2.0(开发中,2026-04-07)
|
||||
|
||||
- **关键词检索**:主界面增加搜索框,按任务标题实时过滤;采用“命中即显示(含上下文)”策略;支持 Esc 清空;英文大小写不敏感。
|
||||
- **云同步(基础可用)**:新增“云同步设置”弹窗,支持手动配置服务端地址(格式校验 + 保存时可达性/风险提示);登录成功后拉取云端任务并刷新主界面(v1.2.0 为只读展示)。
|
||||
- **云同步(基础可用)**:新增“云同步设置”弹窗,支持手动配置服务端地址(格式校验 + 保存时可达性/风险提示);登录成功后拉取云端任务并刷新主界面(v1.2.0 为只读展示);401/403 时会自动清会话并弹出登录入口。
|
||||
- **MAUI(Windows)内嵌 API 文档**:Debug 模式下,内嵌 WebServer 默认提供 Swagger UI(`{HostUrl}/swagger`)与 OpenAPI JSON(`{HostUrl}/swagger/v1/swagger.json`),便于本地接口调试。
|
||||
- **Swagger 输出补齐 Dynamic API**:任务管理等 Dynamic API 端点会出现在 `swagger.json` 中,避免“接口缺失”导致联调困难。
|
||||
- **SPA 路由回落行为修复**:当 Release/非 Debug 未启用 Swagger 时,`/swagger` 不再被当作“后端专用路径”排除,访问会按 SPA 路由规则回落到 `/index.html`,避免直接 404。
|
||||
- **MAUI 多平台构建开关**:在 Windows 开发机上默认仅构建 Android + Windows 目标,避免 iOS/MacCatalyst 目标在非 macOS 环境触发运行时包缺失(NETSDK1082);在 macOS 上仍会包含 iOS/MacCatalyst 目标。
|
||||
- **发布脚本整理**:拆分/对齐各平台发布入口,新增 `publish.ps1` 作为统一入口(默认发布 Windows + Linux),Windows 发布脚本支持开关打包与版本自增,发布产物会落盘到 `artifacts/`。
|
||||
- **Windows 发布打包修复**:Inno Setup 安装包文件名带版本号(Hua.Todo_Setup_vX.Y.Z.exe);安装后快捷方式/启动项指向 Hua.Todo.Maui.exe;发布产物强制 IsUsingStatic=true。
|
||||
- **Windows WebView2 数据目录调整**:MAUI(Unpackaged)默认会在安装目录生成 `Hua.Todo.Maui.exe.WebView2`;现改为写入 `%LocalAppData%\Hua.Todo\WebView2`,避免污染安装目录。
|
||||
- **Windows WebView2 Runtime 误判修复**:当系统已安装 WebView2 Runtime 但发布产物缺少/裁剪 WebView2 托管程序集时,旧检测逻辑会误判为“未安装”;现改为优先从常见安装目录探测 Evergreen 版本,避免阻断主界面加载。
|
||||
- **Windows 三件套开发体验**:新增 `start-host.ps1` / `start-dev.ps1`,并在 MAUI 中约定 `IsUsingStatic=false` 时不启动内置 WebServer,避免注入覆盖 Vite 的 `/api -> 5173` 代理配置。
|
||||
- **Avalonia 桌面交互对齐 MAUI**:增加托盘菜单(显示/退出)、关闭隐藏到托盘、Windows 全局热键唤起主窗口、热键配置本地持久化;并对齐 Avalonia 的 appsettings 默认值。
|
||||
|
||||
### v1.1.1 (2026-04-06)
|
||||
|
||||
Reference in New Issue
Block a user