feat: make spatial entry optional and authoritative
This commit is contained in:
@@ -9,7 +9,7 @@ from sqlalchemy.orm import Session
|
||||
from app.db.session import get_db
|
||||
from app.models import Area
|
||||
from app.schemas import Envelope
|
||||
from app.schemas.area import AreaCreate, AreaList, AreaRead, AreaUpdate
|
||||
from app.schemas.area import AreaCreate, AreaList, AreaRead, AreaUpdate, MunicipalitySearchList
|
||||
from app.services.area_service import AreaService
|
||||
from app.utils.response import envelope
|
||||
|
||||
@@ -33,6 +33,23 @@ def create_area(project_id: UUID, payload: AreaCreate, db: Session = Depends(get
|
||||
return envelope(AreaService.serialize_area(area))
|
||||
|
||||
|
||||
@router.get("/municipalities", response_model=Envelope[MunicipalitySearchList])
|
||||
def search_municipalities(
|
||||
project_id: UUID,
|
||||
query: str = Query(default="", max_length=120),
|
||||
limit: int = Query(default=20, ge=1, le=50),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
items, total = AreaService.search_municipalities(db, project_id, query, limit)
|
||||
return envelope({"items": items, "total": total})
|
||||
|
||||
|
||||
@router.post("/municipalities/{niscode}/activate", response_model=Envelope[AreaRead])
|
||||
def activate_municipality(project_id: UUID, niscode: str, db: Session = Depends(get_db)):
|
||||
area = AreaService.activate_municipality(db, project_id, niscode)
|
||||
return envelope(AreaService.serialize_area(area))
|
||||
|
||||
|
||||
@router.get("/{area_id}", response_model=Envelope[AreaRead])
|
||||
def get_area(
|
||||
project_id: UUID,
|
||||
|
||||
Reference in New Issue
Block a user