controller.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:restful-api 作者: TeamGhostBuster 项目源码 文件源码
def add_comment(user, article_id):
    """
    @api {post} /article/:id/comment Post comment to an article
    @apiName Post comment to an article
    @apiGroup Comment

    @apiUse AuthorizationTokenHeader

    @apiParam {String} id Article unique ID.
    @apiParam {String} comment The comment to be added
    @apiParam {Boolean} public The privacy setting for the comment, default is True
    @apiParamExample Request (Example)
        {
            "comment": "I hate you",
            "public": "false"
        }

    @apiUse UnauthorizedAccessError
    @apiUse ResourceDoesNotExist
    @apiUse BadRequest
    """
    app.logger.info('User {} Access {}'.format(user, request.full_path))

    # Get request body
    req = RequestUtil.get_request()
    comment = req.get('comment')
    public = req.get('public')

    # Add comment
    result = MongoUtil.add_comment(user, article_id, comment, public)

    # If error occurs
    if isinstance(result, str):
        return ResponseUtil.error_response(result)

    app.logger.info('User {} Create comment {}'.format(user, result.id))
    return jsonify(JsonUtil.serialize(result))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号