refactor: 重构待办事项模块结构与命名

This commit is contained in:
ShaoHua
2026-04-08 19:59:50 +08:00
parent 7a4c516a20
commit 04263dff4e
30 changed files with 888 additions and 320 deletions
+11 -11
View File
@@ -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();