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))
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))
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))
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))
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))
def visible(db: Session, poster_id: int, is_content: bool, new_visible: int): """ """ # is_content: 是否是更改content_visible字段 -- true: 是,false: 不是 # 1. check authority auth_usecase.has_authority(db, 'change_visible', poster_id) # 2. get basic m_poster = obtain.obtain_simple(db, poster_id=poster_id) if m_poster is None: raise exception.NoExistPoster(poster_id) # 3. update content || update picvid if is_content == VisiblePart.Content.value: org_visible = m_poster.content_visible update_content_visible(db, m_poster, org_visible, new_visible) else: org_visible = m_poster.picvid_visible update_picvid_visible(db, m_poster, org_visible, new_visible)
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))
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))
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))
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))
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}))
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))