Ejemplo n.º 1
0
def preparing(db: Session, obj_list: str, visible_bucket: str):
    """ 尝试准备数据,并根据需求添加filter,允许准备失败返回默认值
        应对 视频id 找不到对应记录而引发的错误 
        视频准备失败不应该引发poster报错
        1. add the filter 
        2. try dealing
    """
    data = []
    # 1. filter
    if obj_list is None:
        return data

    if obj_list == '':
        return data

    # 2. try dealing the data
    try:
        data = [
            _video_id_to_dict(db, int(i), visible_bucket)
            for i in obj_list.split(',')
        ]
    except Exception as e:
        data = [{} for i in obj_list.split(',')]
        logworker.exception("preparing video")
        logworker.error([obj_list, visible_bucket])

    return data
Ejemplo n.º 2
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))
Ejemplo n.º 3
0
def delete_public(keys: List):
    """"""
    ret, info = qiniu_multi.multi_delete(
        VisibleBucket.Public.value, keys)

    if info.status_code != 200:
        logworker.error('delete_public: ' +
                        str(keys) + ' : ' + info.text_body)
Ejemplo n.º 4
0
def copy_to_public(keys: List):
    """"""
    ret, info, public_key_list = qiniu_multi.multi_copy(keys)
    if info.status_code != 200:
        logworker.error('copy_to_public: ' +
                        str(keys) + ' : ' + info.text_body)

    return public_key_list
Ejemplo n.º 5
0
def reply_post():
    # 1. check data
    try:
        req = ReplyPostSchema().load(request.json)
    except marshmallow.ValidationError as err:
        logworker.error(request.json)
        return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages))

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

    # temp!?. can it reply again?
    if reply_usecase.has_already_submit(g.db, req.poster_id) is True:
        return jsonify(ErrorResponse(error.MoretimeReplyOnlyOnce))

    # 3. querying
    try:
        reply = reply_usecase.submit(
            g.db, request.current_user_id, req)
    except exception.MoretimeException as exc:
        logworker.error(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

    # 5. set content visible [force!] 第一条评论更新文字可见性
    if req.prior_id == ReplyToPoster.Prior.value:
        # 有可能是第一条评论
        if reply_usecase.is_first_submit(g.db, req.poster_id) is True:
            try:
                poster_usecase.visible(
                    g.db, req.poster_id,
                    VisiblePart.Content.value, PublicVisible.Yes.value,)
            except exception.MoretimeException as exc:
                logworker.error(req)
                return jsonify(ErrorResponse(exc.error, data=str(exc)))

    # 6. set picvid visible    异步
    if req.set_visible is not None:
        try:
            poster_usecase.visible(
                g.db, req.poster_id,
                VisiblePart.Media.value, SET_VISIBLE[req.set_visible])
        except exception.MoretimeException as exc:
            logworker.error(req)
            return jsonify(ErrorResponse(exc.error, data=str(exc)))

    result = ReplyCreateSchema().dump(
        {'reply_id': reply.id, 'to_user_id': reply.to_user_id})

    return jsonify(DataResponse(result))
Ejemplo n.º 6
0
def poster_visible():
    # 1. check data - poster id
    try:
        req = PosterVisibleSchema().load(request.json)
    except marshmallow.ValidationError as err:
        logworker.error(request.json)
        return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages))

    # 2. check authorty
    # None 由visible控制是否可以操作

    # 3. update querying
    try:
        poster_usecase.visible(
            g.db, req.poster_id, req.is_content, SET_VISIBLE[req.set_visible])
    except exception.MoretimeException as exc:
        logworker.exception(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

    return jsonify(OKResponse(True))
Ejemplo n.º 7
0
def order_poster_get():
    # 1. check data
    try:
        req = OrderGetSchema().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_order_poster', req.order_no)
    except exception.AuthorityException as exc:
        logworker.error(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

    # 3. querying
    data = poster_usecase.obtain(g.db, order_no=req.order_no)

    return jsonify(DataResponse(data))
Ejemplo n.º 8
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))
Ejemplo n.º 9
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))
Ejemplo n.º 10
0
def poster_get():
    # 1. check data - poster id
    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
    poster = poster_usecase.obtain(g.db, poster_id=req.poster_id)

    # 4. prepare return data
    data = PosterSchema().dump(poster)

    return jsonify(DataResponse(data))
Ejemplo n.º 11
0
def poster_delete():
    # 1. check data - poster id
    try:
        req = PosterDeleteSchema().load(request.json)
    except marshmallow.ValidationError as err:
        logworker.error(request.json)
        return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages))

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

    # querying
    try:
        poster_usecase.delete(g.db, req.poster_id)
    except exception.MoretimeException as exc:
        logworker.exception(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

    return jsonify(OKResponse(True))
Ejemplo n.º 12
0
def preparing(db, obj_list):
    """ 尝试准备数据,并根据需求添加filter,允许准备失败返回默认值
        应对 图片id 找不到对应记录而引发的错误 
        图片准备失败不应该引发poster报错
        1. add the filter 
        2. try dealing
    """
    data = []
    # 1. filter
    if obj_list is None:
        return data

    if obj_list == '':
        return data

    # 2. try dealing the data
    try:
        data = [_picture_id_to_dict(db, int(i)) for i in obj_list.split(',')]
    except Exception as e:
        data = [{} for i in obj_list.split(',')]
        logworker.exception("preparing picture")
        logworker.error([obj_list])

    return data
Ejemplo n.º 13
0
def reply_delete():
    # 1. check data
    try:
        req = ReplyDeleteSchema().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, 'delete_reply', req.reply_id)
    except exception.MoretimeException as exc:
        logworker.error(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

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

    return jsonify(OKResponse(True))
Ejemplo n.º 14
0
def poster_post():

    # 1. check data
    try:
        req = PosterPostSchema().load(request.json)
    except marshmallow.ValidationError as err:
        logworker.error(request.json)
        return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages))

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

    # 3. create querying
    try:
        poster = poster_usecase.submit(g.db, request.current_user_id, req)
    except exception.MoretimeException as exc:
        logworker.error(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

    # 4. create querying    #【这里尝试使用异步的方式调用】【去除】 此时可以返回了
    try:
        order_usecase.submit(
            g.db, req.order_no, poster.id,
            request.current_user_id, poster.to_user_id)
    except exception.MoretimeException as exc:
        logworker.exception(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

    #result = PosterCreateSchema().dump(poster.id)

    return jsonify(DataResponse({"posterID": poster.id}))
Ejemplo n.º 15
0
def rate_post():
    # 1. check data
    try:
        req = RatePostSchema().load(request.json)
    except marshmallow.ValidationError as err:
        logworker.error(request.json)
        return jsonify(ErrorResponse(error.InvalidParameter,
                                     data=err.messages))

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

    # 3. create rate
    try:
        rate_usecase.submit_rate(g.db, req.order_no, req.rate)
    except exception.MoretimeOrderException as exc:
        logworker.error(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

    return jsonify(OKResponse(True))