Exemple #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))
Exemple #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))
Exemple #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))
Exemple #4
0
def poster_user_get():

    # 1. check data - offset limit
    try:
        req = PageRequestSchema().load(request.args)
    except marshmallow.ValidationError as err:
        logworker.exception(request.args)
        return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages))

    # 2. check authority
    # None 查看自己的 不用验证

    # 3. querying
    try:
        data = poster_usecase.obtain(
            g.db, to_user_id=request.current_user_id,
            visible=RoleVisible.Buyer.value, offset=req.offset, limit=req.limit)
    except exception.MoretimeException as exc:
        logworker.exception(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

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

    return jsonify(DataResponse(data))
Exemple #5
0
def poster_reply():
    """summary: 同时获得指定poster内容和它的所有回复 分享页H5"""
    # 1. check data
    try:
        req = PosterGetSchema().load(request.args)
    except marshmallow.ValidationError as err:
        logworker.exception(request.args)
        return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages))

    # 2. check authority 目前是否可查看
    try:
        auth_usecase.has_authority(
            g.db, 'obtain_poster_public', req.poster_id)
    except exception.MoretimeException as exc:
        logworker.exception(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

    # 3. query
    try:
        data = poster_usecase.obtain(
            g.db, poster_id=req.poster_id,
            visible=VisibleLevel.Public.value, share=True, wechat=True)
    except exception.MoretimeException as exc:
        logworker.exception(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

    data = PosterAndReplySchema().dump(data)

    return jsonify(DataResponse(data))
Exemple #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))
Exemple #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))
Exemple #8
0
def handle_error(exc):
    code = 500
    if isinstance(exc, HTTPException):
        code = exc.code

    traceback.print_exc()

    data = dict(
        error=str(exc),
        code=code
    )
    return jsonify(ErrorResponse(error.UnknownError, data=data))
Exemple #9
0
def poster_share():
    """ """
    # 1. check data
    try:
        req = PosterGetSchema().load(request.args)
    except marshmallow.ValidationError as err:
        logworker.exception(request.args)
        return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages))

    # 2. check authority 使用[更改可见性]权限
    try:
        auth_usecase.has_authority(
            g.db, 'change_visible', req.poster_id)
    except exception.MoretimeException as exc:
        logworker.exception(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

    # 3. change visible
    try:
        poster_usecase.visible(
            g.db, req.poster_id,
            VisiblePart.Media.value, PublicVisible.Yes.value)
    except exception.MoretimeException as exc:
        logworker.exception(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

    # 4. query share information
    try:
        data = poster_usecase.obtain(
            g.db, poster_id=req.poster_id, share=True,
            visible=VisibleLevel.Private.value)
    except exception.MoretimeException as exc:
        logworker.exception(req)
        return jsonify(ErrorResponse(exc.error, data=str(exc)))

    data = PosterShareSchema().dump(data)

    return jsonify(DataResponse(data))
Exemple #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))
Exemple #11
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))
Exemple #12
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))
Exemple #13
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}))
Exemple #14
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))
Exemple #15
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))