feat(children): support soft delete child profiles

This commit is contained in:
stu2not
2026-05-25 17:27:12 +08:00
parent 5d86ee5826
commit 8cff60f87b
4 changed files with 96 additions and 5 deletions

View File

@@ -52,11 +52,11 @@ class ChildService(DatabaseServiceBase):
finally:
await db_session.close()
async def get(self, child_id: int) -> Optional[Mapping]:
async def get(self, child_id: int, user_id: int) -> Optional[Mapping]:
db_session = await self.get_session()
try:
dao = ChildDAO(db_session)
return await dao.get_by_id(child_id)
return await dao.get_by_parent(child_id, user_id)
finally:
await db_session.close()
@@ -75,6 +75,21 @@ class ChildService(DatabaseServiceBase):
raise PermissionError("No access to this child")
await dao.update(child_id, child_name, child_gender, child_birthday)
await db_session.commit()
return await self.get(child_id)
return await self.get(child_id, user_id)
finally:
await db_session.close()
async def delete(self, child_id: int, user_id: int) -> bool:
db_session = await self.get_session()
try:
dao = ChildDAO(db_session)
deleted = await dao.soft_delete_for_parent(child_id, user_id)
if not deleted:
return False
await db_session.commit()
return True
except Exception:
await db_session.rollback()
raise
finally:
await db_session.close()