Skip to content

Commit

Permalink
refactor: add task details to project schema output
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Nov 29, 2023
1 parent 079617e commit fbb8b84
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/backend/app/db/postgis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with FMTM. If not, see <https:#www.gnu.org/licenses/>.
#
"""PostGIS and geometry handling helper funcs."""

import datetime

Expand All @@ -25,11 +26,15 @@


def timestamp():
"""Used in SQL Alchemy models to ensure we refresh timestamp when new models initialised."""
"""Get the current time.
Used to insert a current timestamp into Pydantic models.
"""
return datetime.datetime.utcnow()


def geometry_to_geojson(geometry: Geometry, properties: str = {}, id: int = None):
"""Convert SQLAlchemy geometry to GeoJSON."""
if geometry:
shape = to_shape(geometry)
geojson = {
Expand All @@ -40,15 +45,19 @@ def geometry_to_geojson(geometry: Geometry, properties: str = {}, id: int = None
# "bbox": shape.bounds,
}
return Feature(**geojson)
return {}


def get_centroid(geometry: Geometry, properties: str = {}):
def get_centroid(geometry: Geometry, properties: str = {}, id: int = None):
"""Convert SQLAlchemy geometry to Centroid GeoJSON."""
if geometry:
shape = to_shape(geometry)
point = shape.centroid
geojson = {
"type": "Feature",
"geometry": mapping(point),
"properties": properties,
"id": id,
}
return Feature(**geojson)
return {}
4 changes: 4 additions & 0 deletions src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# You should have received a copy of the GNU General Public License
# along with FMTM. If not, see <https:#www.gnu.org/licenses/>.
#
"""Logic for FMTM project routes."""

import io
import json
import os
Expand Down Expand Up @@ -1919,6 +1921,8 @@ async def convert_to_app_project(db_project: db_models.DbProject):
db_project.outline, {"id": db_project.id}, db_project.id
)

app_project.project_tasks = db_project.tasks

return app_project


Expand Down

0 comments on commit fbb8b84

Please sign in to comment.