Skip to content

Commit f894136

Browse files
committed
Fix: update parent to save has_subsections when adding a new section
- Fix typing
1 parent 6d1fc95 commit f894136

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

check.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ ruff format && \
22
ruff check --fix && \
33
mypy planty && \
44
pytest -x && \
5+
cd frontend && \
6+
npm run build && \
57
echo "All right, ready to commit!"

planty/application/services/tasks.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,15 @@ def __init__(self, uow: IUnitOfWork):
143143
self._section_repo = uow.section_repo
144144
self._task_repo = uow.task_repo
145145

146-
# TODO: when writing "update_section" don't forget to raise
147-
# ChangingRootSectionError if root section is being updated
148-
149146
async def add(self, user_id: UUID, section_data: SectionCreateRequest) -> Section:
150-
if parent_id := section_data.parent_id:
151-
parent_section = await self._section_repo.get(
152-
parent_id, with_direct_subsections=True
153-
)
154-
if parent_section.user_id != user_id:
155-
raise ForbiddenException()
156-
# add to the end of parent section:
157-
index = await self._section_repo.count_subsections(parent_section.id)
158-
else:
159-
index = 0
147+
parent_section = await self._section_repo.get(
148+
section_data.parent_id, with_direct_subsections=True
149+
)
150+
if parent_section.user_id != user_id:
151+
raise ForbiddenException()
152+
# add to the end of parent section:
153+
index = await self._section_repo.count_subsections(parent_section.id)
154+
160155
section = Section(
161156
user_id=user_id,
162157
title=section_data.title,
@@ -170,8 +165,10 @@ async def add(self, user_id: UUID, section_data: SectionCreateRequest) -> Sectio
170165
section, index
171166
) # this line checks constraints of parent_section
172167
await self._section_repo.add(section, index=index)
168+
await self._section_repo.update(parent_section)
173169
return section
174170

171+
# TODO: raise ChangingRootSectionError if root section is being updated
175172
async def update_section(
176173
self, user_id: UUID, section_data: SectionUpdateRequest
177174
) -> SectionResponse:

planty/scripts/create_admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def create_admin(
3939
hide_input=True,
4040
confirmation_prompt=True,
4141
),
42-
):
42+
) -> None:
4343
asyncio.run(create_admin_user(email, password))
4444

4545

0 commit comments

Comments
 (0)