新增api查看是否已经点赞

Change-Id: Ibc81bf669bdfe6061c84c80e11199fdfd19c0cb1
diff --git a/WZY/xhs_server/routes/posts.py b/WZY/xhs_server/routes/posts.py
index 11c0b9e..cb7e266 100644
--- a/WZY/xhs_server/routes/posts.py
+++ b/WZY/xhs_server/routes/posts.py
@@ -149,4 +149,23 @@
     post = Post.query.get_or_404(post_id)
     post.heat = max(post.heat - 1, 0)
     db.session.commit()
-    return '', 204
\ No newline at end of file
+    return '', 204
+
+@posts_bp.route('/<int:post_id>/like', methods=['GET'])
+def has_liked(post_id):
+    """
+    检查指定 user_id 是否对 post_id 点过赞。
+    GET /posts/<post_id>/like?user_id=123
+    返回 { "liked": true } 或 { "liked": false }
+    """
+    user_id = request.args.get('user_id', type=int)
+    if not user_id:
+        abort(400, 'user_id required')
+
+    exists = Behavior.query.filter_by(
+        user_id=user_id,
+        post_id=post_id,
+        type='like'
+    ).first() is not None
+
+    return jsonify({'liked': exists}), 200