点赞相关:
后端Flask代码:
from . import blue_news
from flask import current_app, g, jsonify, request
from info.models import Comment, CommentLike
from info.utils.comment import check_login
from info import db
from info.response_code import RET
@blue_news.route('/comment_like', methods=["POST"])
@check_login
def comment_like():
"""
评论点赞
1.校验用户登录状态
2.接收参数(comment_id, action)
3.校验参数(comment_id, action)
3.1 参数是否齐全
3.2 comment_id是否为整型
3.3 action是否合法(add, remove)
3.4 是否存在这条评论
4.根据action执行操作
5.返回结果
:return:
"""
# 1.校验用户登录状态
user = g.user
if not user:
return jsonify(errno=RET.SESSIONERR, errmsg="用户未登录")
# 2.接收参数(comment_id, action)
comment_id = request.j