From abd0ed882f155a7f9c56e98f3ca318cf705185d3 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Thu, 26 Mar 2026 14:53:55 +0000 Subject: [PATCH] get uprn from pashub job id --- backend/pashub_fetcher/handler/handler.py | 10 ++++++++-- backend/pashub_fetcher/pashub_client.py | 15 +++++++++++++++ .../pashub_to_ara_trigger_request.py | 9 +++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 backend/pashub_fetcher/pashub_to_ara_trigger_request.py diff --git a/backend/pashub_fetcher/handler/handler.py b/backend/pashub_fetcher/handler/handler.py index 38b79ab4..8a02ce72 100644 --- a/backend/pashub_fetcher/handler/handler.py +++ b/backend/pashub_fetcher/handler/handler.py @@ -1,6 +1,6 @@ import os import re -from typing import Any, Dict, List, Mapping +from typing import Any, Dict, List, Mapping, Optional from openpyxl import load_workbook from backend.pashub_fetcher.job import Job @@ -80,10 +80,16 @@ def handler(event: Mapping[str, Any], context: Any) -> None: for job in jobs: try: + job_id = job["id"] + uprn: Optional[str] = pashub_client.get_uprn_by_job_id(job_id) + logger.info(f"Got UPRN {uprn} for job {job_id}") + job_files: List[str] = pashub_client.get_core_evidence_files_by_job_id( - job["id"] + job_id ) + # Upload files to s3 + # Upload files to sharepoint job_path = f"{BASE_PATH}/{job['address']}" diff --git a/backend/pashub_fetcher/pashub_client.py b/backend/pashub_fetcher/pashub_client.py index efc21803..20b8590d 100644 --- a/backend/pashub_fetcher/pashub_client.py +++ b/backend/pashub_fetcher/pashub_client.py @@ -71,6 +71,21 @@ class PashubClient: return saved_files + def get_uprn_by_job_id(self, job_id: str) -> Optional[str]: + logger.info(f"Getting UPRN for job ID {job_id}") + url = f"{self.base}/jobs/{job_id}" + + r = self.session.get(url) + if r.status_code == 401: + raise UnauthorizedError("Token expired or invalid") + + r.raise_for_status() + + try: + return r.json()["uprn"] + except Exception: + return None + def _get_core_file_type(self, file: EvidenceFileData) -> Optional[CoreFiles]: for core_file in CoreFiles: if file.file_name.startswith(core_file.value): diff --git a/backend/pashub_fetcher/pashub_to_ara_trigger_request.py b/backend/pashub_fetcher/pashub_to_ara_trigger_request.py new file mode 100644 index 00000000..d97281fd --- /dev/null +++ b/backend/pashub_fetcher/pashub_to_ara_trigger_request.py @@ -0,0 +1,9 @@ +from typing import Optional + +from pydantic import BaseModel + + +class PashubToAraTriggerRequest(BaseModel): + pashub_job_id: str + + sharepoint_url: Optional[str] = None