Exemplo n.º 1
0
def reply_get():
    ''' obtain by reply id'''
    # 1. check data
    try:
        req = ReplyGetSchema().load(request.args)
    except marshmallow.ValidationError as err:
        logworker.error(request.args)
        return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages))

    # 2. check authority
    try:
        auth_usecase.has_authority(
            g.db, 'obtain_reply', req.poster_id)
    except exception.MoretimeException as exc:
        logworker.error(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

    # 3. querying
    try:
        data = reply_usecase.obtain(
            g.db, reply_id=req.reply_id)
    except exception.MoretimeException as exc:
        logworker.error(req)
        return jsonify(ErrorResponse(error.MoretimeReplySubmitFailed, data=str(exc)))

    # 4. prepare return data
    data = ReplySchema(many=True).dump(data)

    return jsonify(DataResponse(data))
Exemplo n.º 2
0
def reply_poster_get():
    # 1. check data
    try:
        req = PosterGetSchema().load(request.args)  # 涉及公众
    except marshmallow.ValidationError as err:
        logworker.error(request.args)
        return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages))

    # 2. check authority
    try:
        auth_usecase.has_authority(
            g.db, 'obtain_poster', req.poster_id)
    except exception.MoretimeException as exc:
        logworker.error(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

    # 3. querying
    try:
        data = reply_usecase.obtain(
            g.db, poster_id=req.poster_id,
            offset=req.offset, limit=req.limit)  # 检查
        # visible=VisibleLevel.Private.value)
    except exception.MoretimeException as exc:
        logworker.error(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

    # 4. prepare return data
    data = PosterReplyRateSchema(many=True).dump(data)

    return jsonify(DataResponse(data))
Exemplo n.º 3
0
def reply_user_get():
    # 1. check data
    try:
        req = ReplyToUserGetSchema().load(request.args)  # 涉及公众
    except marshmallow.ValidationError as err:
        logworker.error(request.args)
        return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages))

    # 2. check authority
    # None  任何身份都可以尝试访问

    # 3. querying
    try:
        data = reply_usecase.obtain(
            g.db, to_user_id=req.user_id,
            visible=VisibleLevel.Public.value,
            offset=req.offset, limit=req.limit)  # 检查
    except exception.MoretimeException as exc:
        logworker.error(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

    # 4. prepare return data
    data = PosterReplyRateSchema(many=True).dump(data)

    return jsonify(DataResponse(data))
Exemplo n.º 4
0
def obtian_poster_reply_by_id(db, poster_id, visible):
    """ 加入reply_list """
    poster = obtain_by_id(db, poster_id, visible)

    reply_list = reply_usecase.obtain(
        db, poster_id=poster_id, visible=visible)

    data = DictObject(poster=poster, reply_list=reply_list)
    return data