Merge pull request 'project-filters-fix: список org_unit в фильтре проектов with-reports' (#150) from project-filters-fix into test
Reviewed-on: #150
This commit is contained in:
commit
2fd464869d
@ -33,6 +33,20 @@ router = APIRouter(tags=["forms"])
|
||||
FORM3_ALLOWED_SECTIONS = {"q1", "q2", "q3", "q4", "year"}
|
||||
|
||||
|
||||
def _parse_org_units_csv(org_units: Optional[str]) -> Optional[list[int]]:
|
||||
if org_units is None:
|
||||
return None
|
||||
|
||||
values = [value.strip() for value in org_units.split(",") if value.strip()]
|
||||
if not values:
|
||||
return None
|
||||
|
||||
try:
|
||||
return [int(value) for value in values]
|
||||
except ValueError as exc:
|
||||
raise HTTPException(400, "org_units должен содержать ID через запятую") from exc
|
||||
|
||||
|
||||
def _parse_sections(sections: Optional[str]) -> Optional[list[str]]:
|
||||
if not sections:
|
||||
return None
|
||||
@ -74,7 +88,7 @@ async def get_projects(
|
||||
@router.get("/projects/with-reports")
|
||||
async def get_projects_with_reports(
|
||||
year: Optional[int] = None,
|
||||
branch_id: Optional[int] = None,
|
||||
branch_id: Optional[str] = None,
|
||||
limit: Optional[int] = None,
|
||||
offset: Optional[int] = None,
|
||||
status_in: Optional[str] = None,
|
||||
@ -82,6 +96,9 @@ async def get_projects_with_reports(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: AppUser = Depends(get_current_active_user_with_set_db),
|
||||
) -> BaseListResponse[dict]:
|
||||
|
||||
branch_id = _parse_org_units_csv(branch_id)
|
||||
|
||||
project_service = ProjectService(db)
|
||||
status_in = status_in.split(",") if status_in is not None else None
|
||||
count, projects = await project_service.get_list_with_reports(
|
||||
|
||||
@ -42,7 +42,7 @@ class ProjectRepository:
|
||||
def _apply_project_filters(
|
||||
query,
|
||||
year: int | None,
|
||||
branch_id: int | None,
|
||||
branch_id: int | list[int] | None,
|
||||
org_unit_ids: list[int] | None,
|
||||
status_in: list[str] | None = None,
|
||||
search: str | None = None,
|
||||
@ -60,7 +60,11 @@ class ProjectRepository:
|
||||
)
|
||||
)
|
||||
if branch_id is not None:
|
||||
if isinstance(branch_id, int):
|
||||
query = query.where(Project.org_unit_id == branch_id)
|
||||
else:
|
||||
query = query.where(Project.org_unit_id.in_(branch_id))
|
||||
|
||||
if status_in is not None:
|
||||
query = query.where(Project.status.in_(status_in))
|
||||
if search is not None and (normalized_search := search.strip()):
|
||||
|
||||
@ -39,7 +39,7 @@ class ProjectService:
|
||||
self,
|
||||
user: AppUser,
|
||||
year: int | None = None,
|
||||
branch_id: int | None = None,
|
||||
branch_id: int | list[int] | None = None,
|
||||
offset: int | None = None,
|
||||
limit: int | None = None,
|
||||
with_count: bool = False,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user