Ejemplo n.º 1
0
    def create_user(self, nickname: str) -> UserEntity:
        new_user = UserModel()
        new_user.nickname = nickname

        user = rdb.Query(new_user).create()

        return user.to_entity()
Ejemplo n.º 2
0
    def read_task(self, task_id) -> Optional[TaskEntity]:
        task = rdb.Query(TaskModel).filter(
            TaskModel.id == task_id).one_or_none()

        if not task:
            return None

        return task.to_entity()
Ejemplo n.º 3
0
    def get_user(self, user_id: int) -> Optional[UserEntity]:
        user = rdb.Query(UserModel).filter(
            UserModel.id == user_id).one_or_none()

        if user is None:
            return None

        return user.to_entity()
Ejemplo n.º 4
0
    def get_tasks(self, previous_id: int, limit: int) -> List[TaskEntity]:
        query = rdb.Query(TaskModel)

        if previous_id > 0:
            query = query.filter(TaskModel.id > previous_id)

        tasks = query.order_by(TaskModel.id).limit(limit).all()

        return [task.to_entity() for task in tasks]
Ejemplo n.º 5
0
    def create_auth(self, auth: AuthenticationEntity) -> AuthenticationEntity:
        new_auth: AuthenticationModel = AuthenticationModel(
            user_id=auth.user_id,
            category=auth.category,
            identification=auth.identification,
            secret=EncryptHelper().encode(auth.secret),
        )
        auth = rdb.Query(new_auth).create()

        return auth.to_entity()
Ejemplo n.º 6
0
    def find_auth(
        self, category: str, identification: str
    ) -> Optional[AuthenticationEntity]:
        authentication = (
            rdb.Query(AuthenticationModel)
            .filter(AuthenticationModel.identification == identification)
            .filter(AuthenticationModel.category == category)
            .one_or_none()
        )

        return None if authentication is None else authentication.to_entity()
Ejemplo n.º 7
0
    def update_task(self,
                    task_id: int,
                    title: Optional[str] = None,
                    contents: Optional[str] = None) -> Optional[TaskEntity]:
        task = rdb.Query(TaskModel).filter(
            TaskModel.id == task_id).one_or_none()

        if not task:
            return None

        task.title = title if title else task.title
        task.contents = contents if contents else task.contents

        rdb.Query(TaskModel).filter(TaskModel.id == task_id).update({
            TaskModel.title:
            task.title,
            TaskModel.contents:
            task.contents,
        })

        return task.to_entity()
Ejemplo n.º 8
0
 def update_user(self, user_id: int, nickname: str):
     rdb.Query(UserModel).filter(UserModel.id == user_id).update(
         {"nickname": nickname})
Ejemplo n.º 9
0
    def create_task(self, user_id: int, title: str,
                    contents: str) -> TaskEntity:
        new_task = TaskModel(user_id=user_id, title=title, contents=contents)
        task = rdb.Query(new_task).create()

        return task.to_entity()
Ejemplo n.º 10
0
    def delete_all_tasks(self) -> bool:
        rdb.Query(TaskModel).delete()

        return True