@@ -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 :
0 commit comments