diff --git a/mondey_backend/src/mondey_backend/models/milestones.py b/mondey_backend/src/mondey_backend/models/milestones.py index 6a79bd93..58b6da82 100644 --- a/mondey_backend/src/mondey_backend/models/milestones.py +++ b/mondey_backend/src/mondey_backend/models/milestones.py @@ -54,6 +54,7 @@ class MilestoneGroup(SQLModel, table=True): text: Mapped[dict[str, MilestoneGroupText]] = dict_relationship(key="lang_id") milestones: Mapped[list[Milestone]] = back_populates("group") + class MilestoneGroupPublic(SQLModel): id: int text: dict[str, MilestoneGroupTextPublic] = {} @@ -103,12 +104,14 @@ class Milestone(SQLModel, table=True): text: Mapped[dict[str, MilestoneText]] = dict_relationship(key="lang_id") images: Mapped[list[MilestoneImage]] = back_populates("milestone") + class MilestonePublic(SQLModel): id: int expected_age_months: int text: dict[str, MilestoneTextPublic] = {} images: list[MilestoneImagePublic] = [] + class MilestoneAdmin(SQLModel): id: int group_id: int @@ -117,6 +120,7 @@ class MilestoneAdmin(SQLModel): text: dict[str, MilestoneText] = {} images: list[MilestoneImage] = [] + ## MilestoneImage diff --git a/mondey_backend/src/mondey_backend/routers/milestones.py b/mondey_backend/src/mondey_backend/routers/milestones.py index 0273b7fd..417c336a 100644 --- a/mondey_backend/src/mondey_backend/routers/milestones.py +++ b/mondey_backend/src/mondey_backend/routers/milestones.py @@ -44,8 +44,9 @@ def get_milestone(session: SessionDep, milestone_id: int): "/milestone-groups/{child_id}", response_model=list[MilestoneGroupPublic] ) def get_milestone_groups( - session: SessionDep, current_active_user: CurrentActiveUserDep, - child_id: int, + session: SessionDep, + current_active_user: CurrentActiveUserDep, + child_id: int, ): delta_months = 6 child = get_db_child(session, current_active_user, child_id) @@ -70,35 +71,33 @@ def get_milestone_groups( ) ).all() - # compute progress from milestone answers. While this is not - # the most efficient way, it is the least intrusive and concentrates + # compute progress from milestone answers. While this is not + # the most efficient way, it is the least intrusive and concentrates # progress reporting in the least amount of code - this function and the # MilestonAnswerPublic model. - answer_session = ( - get_or_create_current_milestone_answer_session( - session, current_active_user, child_id - ) + answer_session = get_or_create_current_milestone_answer_session( + session, current_active_user, child_id ) - # FIXME: this needs to be done better, as it contains a cumbersome - # type conversion that should be avoided. - # when fixing: -make sure pydantic is still as much in effect as possible + # FIXME: this needs to be done better, as it contains a cumbersome + # type conversion that should be avoided. + # when fixing: -make sure pydantic is still as much in effect as possible # - check if we need it at all. certainly a nice thing milestone_groups_public = [] - for mgroup in milestone_groups: + for mgroup in milestone_groups: p = 0.0 mgroup_public = MilestoneGroupPublic( id=mgroup.id, order=mgroup.order, text=mgroup.text, - milestones=mgroup.milestones + milestones=mgroup.milestones, ) - for milestone in mgroup.milestones: + for milestone in mgroup.milestones: answer = answer_session.answers.get(milestone.id) if answer is not None and answer.answer > 0: - p += 1.0 + p += 1.0 - mgroup_public.progress = p / len(mgroup.milestones) + mgroup_public.progress = p / len(mgroup.milestones) milestone_groups_public.append(mgroup_public) return milestone_groups_public