Skip to content

Commit

Permalink
Created new deps function org_from_project
Browse files Browse the repository at this point in the history
  • Loading branch information
sujanadh committed Jan 23, 2024
1 parent 15478ed commit b7ffc2d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/backend/app/organisations/organisation_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
from sqlalchemy.orm import Session

from app.db.database import get_db
from app.db.db_models import DbOrganisation
from app.db.db_models import DbOrganisation, DbProject
from app.models.enums import HTTPStatus
from app.projects import project_deps


async def get_organisation_by_name(db: Session, org_name: str) -> DbOrganisation:
Expand Down Expand Up @@ -90,3 +91,12 @@ async def org_exists(

log.debug(f"Organisation match: {db_organisation}")
return db_organisation


async def org_from_project(
project: DbProject = Depends(project_deps.get_project_by_id),
db: Session = Depends(get_db),
) -> DbOrganisation:
"""Get an organisation from a project id."""
org_id = project.organisation_id
return await org_exists(org_id, db)
8 changes: 3 additions & 5 deletions src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
from app.db import db_models
from app.db.database import get_db
from app.db.postgis_utils import geojson_to_flatgeobuf, geometry_to_geojson, timestamp
from app.organisations import organisation_deps
from app.projects import project_schemas
from app.s3 import add_obj_to_bucket, get_obj_from_bucket
from app.tasks import tasks_crud
Expand Down Expand Up @@ -2359,11 +2358,10 @@ async def get_pagination(page: int, count: int, results_per_page: int, total: in
return pagination


async def get_dashboard_detail(project: db_models.DbProject, db: Session):
async def get_dashboard_detail(
project: db_models.DbProject, db_organisation: db_models.DbOrganisation, db: Session
):
"""Get project details for project dashboard."""
db_organisation = await organisation_deps.get_organisation_by_id(
db, project.organisation_id
)
s3_project_path = f"/{project.organisation_id}/{project.id}"
s3_submission_path = f"/{s3_project_path}/submission.zip"
s3_submission_meta_path = f"/{s3_project_path}/submissions.meta.json"
Expand Down
9 changes: 7 additions & 2 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from app.central import central_crud
from app.db import database, db_models
from app.models.enums import TILES_FORMATS, TILES_SOURCE, HTTPStatus
from app.organisations import organisation_deps
from app.projects import project_crud, project_deps, project_schemas
from app.projects.project_crud import check_crs
from app.static import data_path
Expand Down Expand Up @@ -1181,20 +1182,24 @@ async def get_template_file(
)
async def project_dashboard(
background_tasks: BackgroundTasks,
project: project_deps.get_project_by_id = Depends(),
project: db_models.DbProject = Depends(project_deps.get_project_by_id),
db_organisation: db_models.DbOrganisation = Depends(
organisation_deps.org_from_project
),
db: Session = Depends(database.get_db),
):
"""Get the project dashboard details.
Args:
background_tasks (BackgroundTasks): FastAPI bg tasks, provided automatically.
project (db_models.DbProject): An instance of the project.
db_organisation (db_models.DbOrganisation): An instance of the organisation.
db (Session): The database session.
Returns:
ProjectDashboard: The project dashboard details.
"""
data = await project_crud.get_dashboard_detail(project, db)
data = await project_crud.get_dashboard_detail(project, db_organisation, db)
background_task_id = await project_crud.insert_background_task_into_database(
db, "sync_submission", project.id
)
Expand Down

0 comments on commit b7ffc2d

Please sign in to comment.