diff --git a/backend/app/api/celestial_body.py b/backend/app/api/celestial_body.py index 351833d..c0a4191 100644 --- a/backend/app/api/celestial_body.py +++ b/backend/app/api/celestial_body.py @@ -58,7 +58,8 @@ async def create_celestial_body( @router.get("/search") async def search_celestial_body( - name: str = Query(..., description="Body name or ID to search in NASA Horizons") + name: str = Query(..., description="Body name or ID to search in NASA Horizons"), + db: AsyncSession = Depends(get_db) ): """ Search for a celestial body in NASA Horizons database by name or ID @@ -68,7 +69,7 @@ async def search_celestial_body( logger.info(f"Searching for celestial body: {name}") try: - result = await horizons_service.search_body_by_name(name) + result = await horizons_service.search_body_by_name(name, db) if result["success"]: logger.info(f"Found body: {result['full_name']}") @@ -111,7 +112,7 @@ async def get_celestial_nasa_data( try: # Fetch raw text from Horizons using the body_id # Note: body.id corresponds to JPL Horizons ID - raw_text = await horizons_service.get_object_data_raw(body.id) + raw_text = await horizons_service.get_object_data_raw(body.id, db) return {"id": body.id, "name": body.name, "raw_data": raw_text} except Exception as e: logger.error(f"Failed to fetch raw data for {body_id}: {e}") diff --git a/backend/app/api/celestial_position.py b/backend/app/api/celestial_position.py index 3904f53..b5de6be 100644 --- a/backend/app/api/celestial_position.py +++ b/backend/app/api/celestial_position.py @@ -342,7 +342,7 @@ async def get_celestial_positions( else: # Download from NASA Horizons - pos_data = await horizons_service.get_body_positions(body.id, start_dt, end_dt, step) + pos_data = await horizons_service.get_body_positions(body.id, db, start_dt, end_dt, step) positions_list = [ {"time": p.time.isoformat(), "x": p.x, "y": p.y, "z": p.z} for p in pos_data diff --git a/backend/app/api/nasa_download.py b/backend/app/api/nasa_download.py index b4fe3d3..ee2c734 100644 --- a/backend/app/api/nasa_download.py +++ b/backend/app/api/nasa_download.py @@ -219,6 +219,7 @@ async def download_positions( # Download from NASA Horizons positions = await horizons_service.get_body_positions( body_id=body_id, + db=db, start_time=target_date, end_time=target_date, step="1d" diff --git a/backend/app/services/nasa_worker.py b/backend/app/services/nasa_worker.py index 6c62b42..088249e 100644 --- a/backend/app/services/nasa_worker.py +++ b/backend/app/services/nasa_worker.py @@ -62,6 +62,7 @@ async def download_positions_task(task_id: int, body_ids: List[str], dates: List # Download positions = await horizons_service.get_body_positions( body_id=body_id, + db=db, start_time=target_date, end_time=target_date, step="1d" diff --git a/backend/app/services/orbit_service.py b/backend/app/services/orbit_service.py index ed03798..09094a2 100644 --- a/backend/app/services/orbit_service.py +++ b/backend/app/services/orbit_service.py @@ -152,6 +152,7 @@ class OrbitService: # Get positions from Horizons (synchronous call) positions = await horizons_service.get_body_positions( body_id=body_id, + db=session, start_time=start_time, end_time=end_time, step=f"{step_days}d"