def test_build_response(app: Flask) -> None: task = Task(1, 1, "title", "contents") output = Success(task) response, status_code = build_response(output, TaskSchema) assert status_code == 200 assert response.json["data"] == task.asdict()
def execute(self, dto: CreateTaskDto) -> Output[Task]: task = self.repository.create_task(dto.user_id, dto.title, dto.contents) if not task: return Failure.build_not_found_error() return Success(task)
def execute(self, dto: GetUserTaskDto) -> Output[List[Task]]: tasks = self.task_repository.get_tasks( previous_id=dto.previous_id, limit=dto.limit ) if len(tasks) < 1: return Failure.build_not_found_error() return Success( data=tasks, meta={"previous_id": tasks[-1].id, "limit": dto.limit} )
def execute(self, dto: CreateTokenDto) -> Output[str]: authentication = self.__repository.find_auth(dto.category, dto.identification) if authentication is None: return Failure.build_not_found_error() if authentication.secret != self.__encrypt_helper.encode(dto.secret): return Failure.build_not_authorized_error() return Success(self.__create_token(authentication.user_id))
def execute(self, dto: UpdateTaskDto) -> Output[Task]: try: self._check_task_authorization(dto) except NotFoundError: return Failure.build_not_found_error() except NotAuthorizedError: return Failure.build_not_authorized_error() try: new_task = self._update_task(dto) except NotFoundError: return Failure.build_not_found_error() return Success(new_task)
def execute(self, token: str) -> Output[Dict[str, int]]: decoded_token = jwt.decode(token, algorithms="HS256") return Success(decoded_token)
def execute(self, dto: UpdateUserDto) -> Output[dict]: self.user_repo.update_user(user_id=dto.user_id, nickname=dto.nickname) return Success({})