fix: 添加删除帖子的 mock handler
- 支持 DELETE /api/posts/:postId 请求 - 从内存存储中正确删除评论 - 修复 mock 模式下删除评论失败的问题 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1541,4 +1541,45 @@ export const eventHandlers = [
|
||||
);
|
||||
}
|
||||
}),
|
||||
|
||||
// 删除帖子/评论
|
||||
http.delete('/api/posts/:postId', async ({ params }) => {
|
||||
await delay(300);
|
||||
const { postId } = params;
|
||||
|
||||
console.log('[Mock] 删除帖子, postId:', postId);
|
||||
|
||||
try {
|
||||
// 从内存存储中删除评论
|
||||
let deleted = false;
|
||||
for (const [eventId, comments] of eventCommentsStore.entries()) {
|
||||
const index = comments.findIndex(c => String(c.id) === String(postId));
|
||||
if (index !== -1) {
|
||||
comments.splice(index, 1);
|
||||
deleted = true;
|
||||
console.log('[Mock] 评论已从事件', eventId, '中删除');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!deleted) {
|
||||
console.log('[Mock] 未找到评论,但仍返回成功(可能是乐观更新的评论)');
|
||||
}
|
||||
|
||||
return HttpResponse.json({
|
||||
success: true,
|
||||
message: '删除成功',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('[Mock] 删除帖子失败:', error);
|
||||
return HttpResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: '删除失败',
|
||||
message: '系统错误,请稍后重试',
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user