Skip to content

Commit

Permalink
feat(project-creation): Enhance schema with new fields and update met…
Browse files Browse the repository at this point in the history
…adata handling
  • Loading branch information
Pradip-p committed Jul 12, 2024
1 parent 092316a commit e26e91f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 31 deletions.
59 changes: 32 additions & 27 deletions src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ async def create_project_with_project_info(
_id = uuid.uuid4()
query = """
INSERT INTO projects (
id, author_id, name, short_description, description, per_task_instructions, status, visibility, outline, dem_url, created
)
id, author_id, name, short_description, description, per_task_instructions, status, visibility, outline, no_fly_zones, dem_url, output_orthophoto_url, output_pointcloud_url, output_raw_url, task_split_dimension, created)
VALUES (
:id,
:author_id,
Expand All @@ -31,36 +30,42 @@ async def create_project_with_project_info(
:status,
:visibility,
:outline,
:no_fly_zones,
:dem_url,
:output_orthophoto_url,
:output_pointcloud_url,
:output_raw_url,
:task_split_dimension,
CURRENT_TIMESTAMP
)
RETURNING id
"""
project_id = await db.execute(
query,
values={
"id": _id,
"author_id": author_id,
"name": project_metadata.name,
"short_description": project_metadata.short_description,
"description": project_metadata.description,
"per_task_instructions": project_metadata.per_task_instructions,
"status": "DRAFT",
"visibility": "PUBLIC",
"outline": str(project_metadata.outline),
"dem_url": project_metadata.dem_url,
},
)

# Fetch the newly created project using the returned ID
select_query = f"""
SELECT id, name, short_description, description, per_task_instructions, outline
FROM projects
WHERE id = '{project_id}'
"""
new_project = await db.fetch_one(query=select_query)
return new_project

try:
project_id = await db.execute(
query,
values={
"id": _id,
"author_id": author_id,
"name": project_metadata.name,
"short_description": project_metadata.short_description,
"description": project_metadata.description,
"per_task_instructions": project_metadata.per_task_instructions,
"status": "DRAFT",
"visibility": "PUBLIC",
"outline": str(project_metadata.outline),
"no_fly_zones": str(project_metadata.no_fly_zones),
"dem_url": project_metadata.dem_url,
"output_orthophoto_url": project_metadata.output_orthophoto_url,
"output_pointcloud_url": project_metadata.output_pointcloud_url,
"output_raw_url": project_metadata.output_raw_url,
"task_split_dimension": project_metadata.task_split_dimension
},
)
return project_id

except Exception as e:
log.exception(e)
raise HTTPException(e) from e

async def get_project_by_id(
db: Database, author_id: uuid.UUID, project_id: Optional[int] = None
Expand Down
8 changes: 4 additions & 4 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def delete_project_by_id(


@router.post(
"/create_project", tags=["Projects"], response_model=project_schemas.ProjectOut
"/create_project", tags=["Projects"]
)
async def create_project(
project_info: project_schemas.ProjectIn,
Expand All @@ -78,14 +78,14 @@ async def create_project(
):
"""Create a project in database."""
author_id = user_data.id
project = await project_crud.create_project_with_project_info(
project_id = await project_crud.create_project_with_project_info(
db, author_id, project_info
)
if not project:
if not project_id:
raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST, detail="Project creation failed"
)
return project
return { "message": "Project successfully created","project_id": project_id}


@router.post("/{project_id}/upload-task-boundaries", tags=["Projects"])
Expand Down
17 changes: 17 additions & 0 deletions src/backend/app/projects/project_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,25 @@ class ProjectIn(BaseModel):
task_split_type: Optional[TaskSplitType] = None
task_split_dimension: Optional[int] = None
dem_url: Optional[str] = None
gsd_cm_px: float = None
is_terrain_follow: bool = False
outline_no_fly_zones: Union[FeatureCollection, Feature, Polygon]
outline_geojson: Union[FeatureCollection, Feature, Polygon]
output_orthophoto_url: Optional[str] = None
output_pointcloud_url: Optional[str] = None
output_raw_url: Optional[str] = None
task_split_dimension: int

@computed_field
@property
def no_fly_zones(self) -> Optional[Any]:
"""Compute WKBElement geom from geojson."""
if not self.outline_no_fly_zones:
return None

outline = merge_multipolygon(self.outline_no_fly_zones)
return geojson_to_geometry(outline)

@computed_field
@property
def outline(self) -> Optional[Any]:
Expand Down

0 comments on commit e26e91f

Please sign in to comment.