Skip to content

Commit

Permalink
Fix: update parent to save has_subsections when adding a new section
Browse files Browse the repository at this point in the history
- Fix typing
  • Loading branch information
m-danya committed Jan 30, 2025
1 parent 6d1fc95 commit f894136
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
2 changes: 2 additions & 0 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ ruff format && \
ruff check --fix && \
mypy planty && \
pytest -x && \
cd frontend && \
npm run build && \
echo "All right, ready to commit!"
23 changes: 10 additions & 13 deletions planty/application/services/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,15 @@ def __init__(self, uow: IUnitOfWork):
self._section_repo = uow.section_repo
self._task_repo = uow.task_repo

# TODO: when writing "update_section" don't forget to raise
# ChangingRootSectionError if root section is being updated

async def add(self, user_id: UUID, section_data: SectionCreateRequest) -> Section:
if parent_id := section_data.parent_id:
parent_section = await self._section_repo.get(
parent_id, with_direct_subsections=True
)
if parent_section.user_id != user_id:
raise ForbiddenException()
# add to the end of parent section:
index = await self._section_repo.count_subsections(parent_section.id)
else:
index = 0
parent_section = await self._section_repo.get(
section_data.parent_id, with_direct_subsections=True
)
if parent_section.user_id != user_id:
raise ForbiddenException()
# add to the end of parent section:
index = await self._section_repo.count_subsections(parent_section.id)

section = Section(
user_id=user_id,
title=section_data.title,
Expand All @@ -170,8 +165,10 @@ async def add(self, user_id: UUID, section_data: SectionCreateRequest) -> Sectio
section, index
) # this line checks constraints of parent_section
await self._section_repo.add(section, index=index)
await self._section_repo.update(parent_section)
return section

# TODO: raise ChangingRootSectionError if root section is being updated
async def update_section(
self, user_id: UUID, section_data: SectionUpdateRequest
) -> SectionResponse:
Expand Down
2 changes: 1 addition & 1 deletion planty/scripts/create_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def create_admin(
hide_input=True,
confirmation_prompt=True,
),
):
) -> None:
asyncio.run(create_admin_user(email, password))


Expand Down

0 comments on commit f894136

Please sign in to comment.