Esempio n. 1
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))
Esempio n. 2
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))
Esempio n. 3
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))
Esempio n. 4
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))
Esempio n. 5
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))