From 2e781ca8093fbe6c5e6fa797c606874fe806c7c1 Mon Sep 17 00:00:00 2001 From: tsygankoviva Date: Thu, 2 Jul 2026 16:44:45 +0300 Subject: [PATCH] =?UTF-8?q?projects-sheets:=20=D0=B3=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=B2=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B5=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B5=D0=BA=D1=82=D0=BE=D0=B2,=20=D0=BE=D0=BF=D1=86?= =?UTF-8?q?=D0=B8=D0=BE=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=B3?= =?UTF-8?q?=D0=BE=D0=B4=20=D0=BF=D1=80=D0=B8=20=D1=81=D0=BE=D0=B7=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/src/domain/schemas.py | 2 +- api/src/repository/project_repository.py | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/api/src/domain/schemas.py b/api/src/domain/schemas.py index d56835e..b11133e 100644 --- a/api/src/domain/schemas.py +++ b/api/src/domain/schemas.py @@ -362,7 +362,7 @@ class AddProjectBody(BaseModel): max_length=30, pattern=r"^[^+\-\/\\=&*\s]{1,30}$", ) - year: int + year: int = Field(default_factory=lambda: datetime.now().year) branch_id: int level: Literal["project", "program"] = "project" parent_id: Optional[int] = None diff --git a/api/src/repository/project_repository.py b/api/src/repository/project_repository.py index 1faae5e..f0492bf 100644 --- a/api/src/repository/project_repository.py +++ b/api/src/repository/project_repository.py @@ -14,7 +14,7 @@ class ProjectRepository: self.db = db @staticmethod - def _serialize_project(project: Project, org_unit_name: str | None, report_count: int) -> dict: + def _serialize_project(project: Project, org_unit_name: str | None, report_count: int, years: list[InterruptedError] | None = None) -> dict: return { "id": project.id, "name": project.name, @@ -29,6 +29,7 @@ class ProjectRepository: "org_unit_id": project.org_unit_id, "org_unit_name": org_unit_name, "report_count": int(report_count), + "years": years, } @staticmethod @@ -66,11 +67,19 @@ class ProjectRepository: .scalar_subquery() ) + report_years_subq = ( + select(RfProjectReport.year) + .where(RfProjectReport.project_id == Project.id) + .distinct() + .scalar_subquery() + ) + query = ( select( Project, OrgUnit.title.label("org_unit_name"), report_count_subq.label("report_count"), + func.array(report_years_subq).label("years"), ) .outerjoin(OrgUnit, OrgUnit.id == Project.org_unit_id) .order_by(Project.id) @@ -82,7 +91,7 @@ class ProjectRepository: query = query.limit(limit) rows = (await self.db.execute(query)).all() - payload = [self._serialize_project(row[0], row[1], row[2]) for row in rows] + payload = [self._serialize_project(row[0], row[1], row[2], row[3]) for row in rows] if not with_count: return payload @@ -101,11 +110,18 @@ class ProjectRepository: .where(RfProjectReport.project_id == Project.id) .scalar_subquery() ) + report_years_subq = ( + select(RfProjectReport.year) + .where(RfProjectReport.project_id == Project.id) + .distinct() + .scalar_subquery() + ) query = ( select( Project, OrgUnit.title.label("org_unit_name"), report_count_subq.label("report_count"), + func.array(report_years_subq).label("years"), ) .outerjoin(OrgUnit, OrgUnit.id == Project.org_unit_id) .where(Project.id == project_id) @@ -117,7 +133,7 @@ class ProjectRepository: row = (await self.db.execute(query)).first() if not row: return None - return self._serialize_project(row[0], row[1], row[2]) + return self._serialize_project(row[0], row[1], row[2], row[3]) async def get_reports(self, project_id: int) -> list[dict]: line_count_subq = (