Пример #1
0
 def transform(self, output: Union[UseCaseSuccessOutput, UseCaseFailureOutput]):
     if isinstance(output, UseCaseSuccessOutput):
         v = output.value
         try:
             schema = PostReportResponseSchema(
                 id=v.id,
                 post_id=v.post_id,
                 report_user_id=v.report_user_id,
                 status=v.status,
                 context=v.context,
                 confirm_admin_id=v.confirm_admin_id,
                 is_system_report=v.is_system_report,
                 created_at=v.created_at,
                 updated_at=v.updated_at,
             )
         except ValidationError as e:
             logger.error(f"[AuthenticationPresenter][transform] error : {e}")
             return failure_response(
                 UseCaseFailureOutput(
                     type=FailureType.SYSTEM_ERROR,
                     message="response schema validation error",
                 )
             )
         result = {
             "data": {"post_report": schema.dict()},
             "meta": {"cursor": output.meta},
         }
         return success_response(result=result)
     elif isinstance(output, UseCaseFailureOutput):
         return failure_response(output=output)
Пример #2
0
def get_post_view(post_id):
    dto = GetPostRequest(post_id=post_id).validate_request_and_make_dto()
    if not dto:
        return failure_response(
            UseCaseFailureOutput(type=FailureType.INVALID_REQUEST_ERROR))

    return PostPresenter().transform(GetPostUseCase().execute(dto=dto))
Пример #3
0
def get_like_post_list_view():
    dto = GetLikePostListRequest(**request.get_json(),
                                 ).validate_request_and_make_dto()
    if not dto:
        return failure_response(
            UseCaseFailureOutput(type=FailureType.INVALID_REQUEST_ERROR))

    return PostListPresenter().transform(
        GetLikePostListUseCase().execute(dto=dto))
Пример #4
0
def create_post_report_view():
    dto = CreatePostReportRequest(
        **request.get_json()).validate_request_and_make_dto()
    if not dto:
        return failure_response(
            UseCaseFailureOutput(type=FailureType.INVALID_REQUEST_ERROR))

    return PostReportPresenter().transform(
        CreatePostReportUseCase().execute(dto=dto))
Пример #5
0
def create_post_view():
    dto = CreatePostRequest(
        **request.form.to_dict(),
        files=request.files.getlist("files"),
    ).validate_request_and_make_dto()
    if not dto:
        return failure_response(
            UseCaseFailureOutput(type=FailureType.INVALID_REQUEST_ERROR))

    return PostPresenter().transform(CreatePostUseCase().execute(dto=dto))
Пример #6
0
 def transform(self, output: Union[UseCaseSuccessOutput,
                                   UseCaseFailureOutput]):
     if isinstance(output, UseCaseSuccessOutput):
         value = output.value
         try:
             schema = PostResponseSchema(post=value)
         except ValidationError as e:
             logger.error(f"[PostPresenter][transform] error : {e}")
             return failure_response(
                 UseCaseFailureOutput(
                     type=FailureType.SYSTEM_ERROR,
                     message="response schema validation error",
                 ))
         result = {
             "data": schema.dict(),
             "meta": output.meta,
         }
         return success_response(result=result)
     elif isinstance(output, UseCaseFailureOutput):
         return failure_response(output=output)
 def transform(
     self,
     response: UseCaseSuccessOutput,
 ):
     try:
         schema = AuthenticationResponseSchema(type=response.type)
     except ValidationError as e:
         logger.error(f"[AuthenticationPresenter][transform] error : {e}")
         return failure_response(
             UseCaseFailureOutput(
                 type=FailureType.SYSTEM_ERROR,
                 message="response schema validation error",
             ))
     result = {
         "data": {
             "result": schema.dict()
         },
         "meta": {
             "cursor": response.meta
         },
     }
     return success_response(result=result)