Skip to content

Commit

Permalink
refactor: better impl for sibling addition
Browse files Browse the repository at this point in the history
  • Loading branch information
kraanzu committed Dec 6, 2024
1 parent ce9d86c commit 78be1ea
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
15 changes: 1 addition & 14 deletions dooit/api/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,7 @@ def _add_sibling(self) -> Self:
raise NotImplementedError # pragma: no cover

def add_sibling(self):
sibling = self._add_sibling()
index = self.order_index

cls = self.__class__
manager.session.query(cls).filter(cls.order_index > index).update(
{cls.order_index: cls.order_index + 1},
synchronize_session=False,
)

sibling.order_index = index + 1
manager.session.add(sibling)
manager.commit()

return sibling
return self._add_sibling()

def shift_down(self) -> bool:
"""
Expand Down
1 change: 1 addition & 0 deletions dooit/api/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def _add_sibling(self) -> "Todo":
todo = Todo(
parent_todo=self.parent_todo,
parent_workspace=self.parent_workspace,
order_index=self.order_index + 1,
)
todo.save()
return todo
Expand Down
1 change: 1 addition & 0 deletions dooit/api/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def add_todo(self) -> "Todo":
def _add_sibling(self) -> "Workspace":
workspace = Workspace(
parent_workspace=self.parent_workspace,
order_index=self.order_index + 1,
)
workspace.save()
return workspace
Expand Down

0 comments on commit 78be1ea

Please sign in to comment.