Add V1 selected area map overlay
GeoIntel CI / docs-smoke (push) Has been cancelled
GeoIntel CI / contract-smoke (push) Has been cancelled

This commit is contained in:
Codex
2026-06-17 00:21:01 +02:00
parent 97be9d9293
commit 47cd2c6c1e
12 changed files with 315 additions and 21 deletions
+16 -9
View File
@@ -3,7 +3,8 @@ from __future__ import annotations
import uuid
from sqlalchemy.orm import Session
from geoalchemy2.shape import from_shape
from geoalchemy2.shape import from_shape, to_shape
from shapely.geometry import mapping
from app.core.errors import AppError
from app.models import Area, Project
@@ -13,7 +14,13 @@ from app.utils.geometry import area_m2, geometry_bbox_polygon, normalize_to_mult
class AreaService:
@staticmethod
def list_areas(db: Session, project_id: uuid.UUID, limit: int = 50, offset: int = 0) -> tuple[list[AreaRead], int]:
def serialize_area(area: Area) -> dict:
payload = AreaRead.model_validate(area).model_dump()
payload["geometry"] = mapping(to_shape(area.geometry)) if area.geometry else None
return payload
@staticmethod
def list_areas(db: Session, project_id: uuid.UUID, limit: int = 50, offset: int = 0) -> tuple[list[Area], int]:
total = db.query(Area).filter(Area.project_id == project_id).count()
areas = (
db.query(Area)
@@ -23,10 +30,10 @@ class AreaService:
.limit(limit)
.all()
)
return [AreaRead.model_validate(area) for area in areas], total
return areas, total
@staticmethod
def create_area(db: Session, project_id: uuid.UUID, payload: AreaCreate) -> AreaRead:
def create_area(db: Session, project_id: uuid.UUID, payload: AreaCreate) -> Area:
if not db.get(Project, project_id):
raise AppError(code="PROJECT_NOT_FOUND", message="Project not found", status_code=404)
@@ -46,17 +53,17 @@ class AreaService:
db.add(area)
db.commit()
db.refresh(area)
return AreaRead.model_validate(area)
return area
@staticmethod
def get_area(db: Session, area_id: uuid.UUID) -> AreaRead:
def get_area(db: Session, area_id: uuid.UUID) -> Area:
area = db.get(Area, area_id)
if not area:
raise AppError(code="AREA_NOT_FOUND", message="Area not found", status_code=404)
return AreaRead.model_validate(area)
return area
@staticmethod
def update_area(db: Session, area_id: uuid.UUID, payload: AreaUpdate) -> AreaRead:
def update_area(db: Session, area_id: uuid.UUID, payload: AreaUpdate) -> Area:
area = db.get(Area, area_id)
if not area:
raise AppError(code="AREA_NOT_FOUND", message="Area not found", status_code=404)
@@ -74,4 +81,4 @@ class AreaService:
db.add(area)
db.commit()
db.refresh(area)
return AreaRead.model_validate(area)
return area