fix(community): persist post liked status in MySQL and local storage to prevent state loss on page switch
这个提交包含在:
@@ -1694,7 +1694,8 @@ app.get('/api/users/:id/finance-records', async (req: Request, res: Response) =>
|
||||
app.get('/api/posts', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const category = req.query.category ? String(req.query.category) : undefined;
|
||||
const posts = await repo.getPosts(category);
|
||||
const userId = Number(req.query.userId || req.headers['x-user-id']) || 1001;
|
||||
const posts = await repo.getPosts(category, undefined, '正常', userId);
|
||||
res.json({
|
||||
code: 20000,
|
||||
data: posts
|
||||
@@ -1804,11 +1805,13 @@ app.post('/api/posts', async (req: Request, res: Response) => {
|
||||
|
||||
app.post('/api/posts/:id/like', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const result = await repo.likePost(String(req.params.id));
|
||||
const userId = Number(req.body?.userId || req.query.userId || req.headers['x-user-id']) || 1001;
|
||||
const action = req.body?.action as 'like' | 'unlike' | undefined;
|
||||
const result = await repo.likePost(String(req.params.id), userId, action);
|
||||
res.json({
|
||||
code: 20000,
|
||||
data: result,
|
||||
message: '点赞成功'
|
||||
message: result.liked ? '点赞成功' : '已取消点赞'
|
||||
});
|
||||
} catch (err: any) {
|
||||
res.status(400).json({ code: 40000, message: err.message });
|
||||
|
||||
在新工单中引用
屏蔽一个用户