def create_user(self, nickname: str) -> UserEntity: new_user = UserModel() new_user.nickname = nickname user = rdb.Query(new_user).create() return user.to_entity()
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()
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()
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]
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()
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()
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()
def update_user(self, user_id: int, nickname: str): rdb.Query(UserModel).filter(UserModel.id == user_id).update( {"nickname": nickname})
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()
def delete_all_tasks(self) -> bool: rdb.Query(TaskModel).delete() return True